home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / doc / sm3doc.me < prev    next >
Encoding:
Text File  |  1996-05-05  |  174.6 KB  |  5,184 lines

  1. \"Macro for putting levels 1 through 4 section headings in t.o.c.
  2. .de $0
  3. .if \\$3=1 \{\
  4. .(x
  5. \fB\\$2  \\$1\fR
  6. .)x 
  7. \}
  8. .if \\$3=2 \{\
  9. .(x
  10.     \fB\\$2\fR  \\$1
  11. .)x
  12. \}
  13. .if \\$3=3 \{\
  14. .(x
  15.         \fB\\$2\fR  \\$1
  16. .)x
  17. \}
  18. .if \\$3=4 \{\
  19. .(x
  20.             \fB\\$2\fR  \\$1
  21. .)x 
  22. \}
  23. ..
  24. \" end macro
  25. .\" use larger type so that it looks OK after photo-reducing
  26. .nr pp 12\" use larger point size
  27. .nr sp 12\" yep, I really mean it
  28. .nr tp 12\" and I'll mean it after other stuff
  29. .nr fp 10\" don't reset to 10 point (and use 9 footnotes)
  30. .sz 12\" believe me!!!
  31. .\"
  32. .\" USING THE EXODUS STORAGE MANAGER
  33. .\"
  34. .\"Macro the the storage manager version number
  35. .ds V "3.1
  36. .po 1.0i
  37. .ll 6.5i
  38. .fo ''%''
  39. .tp
  40. .sp 20
  41. .ls 1
  42. .ce 5
  43. .sz 14
  44. \fBUsing the EXODUS Storage Manager V\*V\fR
  45. .sz 12
  46. (Last revision: November, 1993)
  47. .sp 3
  48. .(f
  49. The Exodus software was developed primarily with funds provided by
  50. by the Defense Advanced Research Projects Agency under contracts 
  51. N00014-85-K-0788, N00014-88-K-0303,  and DAABO7-92-C-Q508 
  52. and monitored by the US Army Research Laboratory.
  53. Additional support was provided by Texas Instruments, Digital Equipment
  54. Corporation, and Apple Computer.
  55. .)f
  56. .bp
  57. .sh 1 "INTRODUCTION"
  58. .lp
  59. The EXODUS Storage Manager
  60. is a multi-user object storage system
  61. supporting versions, indexes, single-site transactions,
  62. distributed transactions, concurrency control, and
  63. recovery.  
  64. This document provides information about using version \*V of 
  65. the EXODUS Storage Manager.
  66. Information about installing the Storage Manager can be found in
  67. the \fIEXODUS Storage Manager Installation Manual\fR.
  68. Section 2 gives an overview of the system.  
  69. Section 3 discusses
  70. configuration facilities.  
  71. Section 4 describes, in detail, the
  72. Storage Manager's application interface.  
  73. Section 5 describes
  74. how to use the Storage Manager server.  
  75. Appendices provide more details on certain aspects of the system.  
  76. A table of contents is located at the end of the document.
  77. .br
  78. .sh 1 "OVERVIEW OF THE EXODUS STORAGE MANAGER"
  79. .lp
  80. This section, an executive summary,
  81. briefly describes the architecture of the
  82. Storage Manager and gives
  83. an overview of the facilities provided 
  84. to applications,
  85. .lp
  86. Version \*V of the Storage Manager runs on the following architectures:
  87. Sun 4 (Sparc) (under SunOS 4.1.[23]),
  88. DecStation 3100/5000 (MIPS) (under Ultrix 4.2), 
  89. and 
  90. HP 720 (under HP-UX A.08.07).
  91. The Storage Manager is written in C++ and had been checked for
  92. compilation under the GNU C++ compiler (g++), version 2.3.3 and 2.4.5.
  93. .sh 2 "Architecture"
  94. .lp
  95. The EXODUS Storage Manager has a client-server architecture.  
  96. An application program that uses the Storage Manager
  97. may reside on a machine different from the machine or machines
  98. on which the Storage Manager server or servers run.
  99. .(x z
  100. application
  101. .)x \*($n
  102. We use the term \fIapplication\fR to refer to programs
  103. that use the Storage Manager through the client programming
  104. interface described in 
  105. Section 4.  
  106. We use the term \fIclient library\fR, or 
  107. .(x z
  108. client, client library
  109. .)x \*($n
  110. \fIclient\fR, to refer to the Storage Manager code and data structures
  111. that are linked into the application program to support the client
  112. programming
  113. interface.  
  114. The client allows applications to use the facilities
  115. described in the next sub-section.  
  116. Each client has its own buffer pool for caching data.  
  117. The client library connects to 
  118. one or more server processes 
  119. and communicates with them using a remote-procedure-call-style 
  120. mechanism that runs over TCP.  
  121. .lp
  122. The Storage Manager server is a multi-threaded process providing
  123. asynchronous I/O, file, transaction, concurrency control, and recovery
  124. services to multiple clients.  
  125. The server stores all data on \fIvolumes\fR,
  126. which are either Unix files or raw disk partitions.
  127. The server is more completely described in 
  128. Section 5 
  129. and in the \fIEXODUS Storage Manager Architecture Overview\fR [exoArch].
  130. .br
  131. .sh 2 "Facilities"
  132. .lp
  133. The EXODUS Storage Manager provides \fIobjects\fR for storing
  134. data, \fIversions\fR of objects, \fIfiles\fR for grouping related
  135. objects, and \fIindexes\fR for supporting efficient object access.  
  136. The Storage Manager also provides \fIvolumes\fR,
  137. \fItransactions\fR, \fIconcurrency control\fR, \fIrecovery\fR, and
  138. \fIconfiguration options\fR.  These facilities are presented briefly in
  139. this section, and more information can be found in later sections of
  140. the document.
  141. .sh 3 "Objects"
  142. .lp
  143. An object is an uninterpreted container of bytes,
  144. which can range in size from a few bytes to 
  145. a little less than the size of a disk.
  146. Internally, the Storage Manager distinguishes two types of objects.
  147. There are \fIsmall objects\fR, which are objects that
  148. fit on a single disk page, and \fIlarge objects\fR, which are objects 
  149. that do not fit on a single disk page.
  150. Support is also provided for creating and manipulating versions of
  151. both small and large objects.
  152. To provide a uniform function call interface, the distinction between 
  153. small, large, and versioned objects is hidden from applications.
  154. Applications are unaware of whether they are dealing with 
  155. a small or large object, and the same interface functions are 
  156. called to manipulate either type of object.
  157. To simplify the task of manipulating very large objects,
  158. the Storage Manager provides flexible buffer management that 
  159. allows variable-length pieces of large objects to be 
  160. buffered contiguously in the client buffer pool. 
  161. .lp
  162. Objects have object identifiers.
  163. The object identifier
  164. of a small object points directly to the object on disk, while the
  165. object identifier
  166. of a large object points to a \fIlarge object header\fR.  
  167. The
  168. header of a large object serves as the root of a 
  169. B\*[+\*]tree 
  170. .(x z
  171. B\*[+\*]tree index
  172. .)x \*($n
  173. .(x z
  174. index, B\*[+\*]tree 
  175. .)x \*($n
  176. index structure that is used to access the object's data
  177. [Care86, Care89].  
  178. For space efficiency, a large object header can
  179. share a disk page with small objects and other large object headers.
  180. The data pages and the pages that make up the index structure of a
  181. large object are not shared, however.  When a small object grows to the
  182. point where it can no longer be stored on a single page, the Storage
  183. Manager automatically converts it to a large object, leaving the new
  184. header in place of the original object.
  185. .lp
  186. The Storage Manager provides functions to read, overwrite, insert,
  187. delete, and append to an object.  
  188. Read requests specify an object identifier and a range of bytes.  
  189. The desired data is read into a contiguous
  190. region in the client buffer pool (even if is distributed over several
  191. disk pages), and a pointer to the data is returned to the caller.  
  192. The overwrite function uses the pointer set up by a read request, and
  193. overwrites a subrange of the data.
  194. The insert and delete functions allow data to be inserted 
  195. into and deleted from objects at arbitrary offsets, while the 
  196. append function allows data to be appended to the end of an object.  
  197. As mentioned earlier,
  198. large objects are represented using a 
  199. B\*[+\*]tree 
  200. index structure.  
  201. This ensures that each of the above operations can be
  202. executed efficiently on large objects.
  203. .sh 3 "Versions"
  204. .lp
  205. A version of an object is another object that appears
  206. to be a copy of the original object.  
  207. A version of a small object is a copy of the original object.  
  208. A version of a large object is an object header with a pointer into
  209. the original object's data, until either the version or the original
  210. object is updated.  
  211. When the large object version is updated, the affected portions of 
  212. the original object are copied
  213. to  prevent the original object from being affected by the
  214. update [Care89].  
  215. Although the version support described here is
  216. primitive, essentially providing \*(lqcopy-on-write\*(rq objects, it has been
  217. purposefully designed that way so that a variety of
  218. application-specific versioning schemes can be implemented on top of
  219. the Storage Manager.  
  220. .sh 3 "Files"
  221. .lp
  222. Objects are allocated in \fIfiles\fR, which are
  223. collections of related objects.  Files have three uses.
  224. .lp
  225. First, files are used for clustering objects.
  226. The objects in a file are stored on disk pages allocated solely to that file,
  227. so files provide a way to physically co-locate related objects on the disk.
  228. .lp
  229. Second, the Storage Manager provides an efficient way to \fIscan\fR
  230. the objects in a file, visiting each object exactly once.
  231. .lp
  232. Third, the Storage Manager offers an efficient mechanism for 
  233. loading the objects into a file in bulk.
  234. .sh 3 "Indexes"
  235. .lp
  236. The Storage Manager provides 
  237. B\*[+\*]tree 
  238. indexes and linear hashing indexes.
  239. .(x z
  240. index, linear hashed
  241. .)x \*($n
  242. .(x z
  243. linear hashed index
  244. .)x \*($n
  245. .(x z
  246. B\*[+\*]tree index
  247. .)x \*($n
  248. .(x z
  249. index, B\*[+\*]tree 
  250. .)x \*($n
  251. Index keys can be any basic C language data type or strings.  
  252. Values can be any type of fixed length.
  253. .sh 3 "Volumes"
  254. .lp
  255. User data and Storage Manager 
  256. meta-data (objects, files, indexes, and logs)
  257. are stored on volumes.  
  258. A volume represents a disk, although in fact it may 
  259. be a Unix raw disk partition or a Unix file.
  260. .lp
  261. Volumes can be \fItemporary\fR, which means
  262. that data stored on them are not logged,
  263. and they do not persist from one transaction to the
  264. next.
  265. Temporary volumes are meant to provide fast
  266. storage for temporary data.
  267. .sh 3 "Transactions"
  268. .lp
  269. A transaction is a set of operations on objects, files, and indexes.  
  270. Transactions are either committed or aborted.  
  271. Updates made by committed transactions are guaranteed to be
  272. reflected on stable storage, even in the event of software or
  273. processor failure.  
  274. Updates made by aborted transactions are not reflected on stable storage.
  275. .lp
  276. Transactions that use data on more than one server are
  277. committed using a distributed two-phase commit protocol [Moha83].
  278. .(x z
  279. two-phase commit protocol
  280. .)x \*($n
  281. .(x z
  282. transactions
  283. .)x \*($n
  284. .(x z
  285. transactions, distributed
  286. .)x \*($n
  287. .(x z
  288. distributed transactions
  289. .)x \*($n
  290. .sh 3 "Concurrency Control"
  291. .lp
  292. Concurrency control allow multiple client applications safely
  293. to use data simultaneously.  
  294. Concurrency control is based on the standard hierarchical two-phase 
  295. locking protocol providing degree-three consistency (see
  296. [Gray78, Gray88]).  
  297. The lock hierarchy contains two granularities: 
  298. file-level, and page-level.  
  299. Locking for index operations is performed with a non-two-phase protocol,
  300. which allows multiple clients to read and update the same index. 
  301. .lp
  302. Deadlocks involving more than one server are resolved through timeouts.
  303. .sh 3 "Recovery"
  304. .lp
  305. The Storage Manager recovers from software, operating system, and
  306. CPU failure by restoring data to a state
  307. in which all transactions have been committed or aborted.
  308. After an application fails, the 
  309. transaction it is running is aborted by the servers
  310. that cooperated in the transaction.  
  311. After a server fails and is restarted,
  312. updates made by committed transactions are restored,
  313. and updates by transactions in progress at the time of failure are undone. 
  314. Recovery from media (disk) failure is not supported.
  315. .sh 3 "Configuration Options"
  316. .lp
  317. The Storage Manager client library and servers have 
  318. \fIconfiguration options\fR, which can be set by users.  
  319. These options control such things as
  320. parameters that affect performance and memory use, 
  321. formats of volumes and logs, 
  322. the choice of servers to be contacted by clients, 
  323. and path names of installed executable files.
  324. .br
  325. .sh 2 "Illustration of Using the Storage Manager"
  326. .lp
  327. The purpose of this section is to give the reader
  328. a context in which to read the rest of this document.
  329. This section illustrates a way to get started using the Storage Manager.
  330. There are many ways to install, configure, and use the 
  331. Storage Manager;
  332. only the simplest way is illustrated here. 
  333. .lp
  334. This section uses an example application, \*(lqproducer-consumer\*(rq.
  335. The source code for the application programs is 
  336. included in the Storage Manager software release, along with other
  337. example applications.
  338. .lp
  339. The producer program generates a series of transactions, each of
  340. which creates an object.  
  341. The consumer program generates a series of transactions,
  342. each of which reads an object and destroys it.  
  343. These programs were selected because they are relatively small, demonstrate
  344. the use of transactions, and show how to respond to
  345. server-initiated transaction failures and
  346. server failures.
  347. .lp
  348. The remainder of this section gives specific directions
  349. for starting a server and running the example
  350. program.
  351. Detailed explanations of the steps are not given here;
  352. all the details are given elsewhere in this document.
  353. .lp
  354. Installing the storage manager is akin to 
  355. installing an operating system or a remote
  356. file system (but it's much simpler).
  357. You need to:
  358. .np
  359. install the system's executable code, libraries,
  360. and include files;
  361. .np
  362. prepare your disks for use;
  363. .np
  364. configure your server so that it will
  365. use your disks, and so that it is otherwise tailored
  366. for your use;
  367. .np
  368. compile and link your application programs to use
  369. the installed system;
  370. .np
  371. configure your application programs' environment, 
  372. run the programs, and 
  373. .np
  374. when you are finished, shut the system down.
  375. .br
  376. .sh 3 "Files Needed"
  377. .lp
  378. The following files are needed to use the Storage Manager: 
  379. .np
  380. \fClibsm_client.a\fR, the Storage Manager client library,
  381. .np
  382. \fCsm_client.h\fR,
  383. the include file containing declarations of key data
  384. structures and constants,
  385. .np
  386. \fCsm_server\fR,
  387. the executable file for the server portion of the Storage Manager,
  388. .np
  389. \fCdiskrw\fR,
  390. the executable file for the disk I/O processes used by the server process, 
  391. .np
  392. \fCformatvol\fR, and a utility program for formatting volumes,
  393. .np
  394. \&\fC.sm_config\fR, configuration files for a server, the formatter, and the
  395. application programs.  
  396. One configuration file can be used for all programs, but it is
  397. sometimes easier to use configuration file for
  398. servers and the formatter, and 
  399. another for applications.
  400. .lp
  401. These files can be installed anywhere; for the purpose of this
  402. section, we assume that they are all installed in your
  403. home directory, along with your application programs.
  404. (See the \fIEXODUS Storage Manager Installation Manual\fR 
  405. to find the files in the Storage Manager software release.)
  406. .br
  407. .sh 3 "Preparing Your Disks"
  408. .lp
  409. The producer and consumer programs
  410. use a volume for storing their objects
  411. with a single server, and
  412. the server uses a log volume.
  413. The \fCformatvol\fR program is used to
  414. format a volume for use as either a data volume or a log volume.
  415. If you plan to use a raw disk partition for either volume, 
  416. ask your system administrator for information
  417. on how to set up the device.
  418. .lp
  419. The formats of the volumes must be
  420. described in the configuration file that 
  421. \fCformatvol\fR reads.
  422. In the directory in which you plan to run \fCformatvol\fR,
  423. create a file called \fC.sm_config\fR that looks something like this,
  424. with the appropriate substitutions:
  425. .(b
  426. .nf
  427. \fC
  428. formatvol*logformat:  /path/to/logfile: 9000: 1: 1: 1000: 8
  429. formatvol*dataformat: /path/to/datafile: 8000: 1: 1: 300
  430. \fR
  431. .)b
  432. .lp
  433. Substitute the pathnames for files that you want to use
  434. for your log volume and data volume.
  435. With the options given above, 
  436. the log volume 
  437. will be given a volume identifier of 9000, 
  438. and will consist of 1 cylinder of 1 track each, with 1000 blocks
  439. on each track, hence, 1000 blocks will be on the log.
  440. The log volume will use 8 Kbyte log pages.  
  441. The data volume will be given a volume identifier of 8000,
  442. and will consist of 1 cylinder of 1 track each, with 300 blocks
  443. on each track, hence, 300 blocks will be on the data volume.
  444. .lp
  445. Now, run the formatter on volumes 9000 and 8000:
  446. .(b
  447. \fCformatvol -vol 9000 -vol 8000\fR
  448. .)b
  449. .lp
  450. If you would like to see the information written on the
  451. volumes' headers, do this:
  452. .(b
  453. \fCformatvol -dis 9000 -dis 8000\fR
  454. .)b
  455. .lp
  456. The formatter prints:
  457. .(b M
  458. \fCVOLID 9000, version 3, is a LOG volume
  459.    BLOCK SIZES: 8 K slotted, 8 K lg data,  8 K lg hdr
  460.            8 K btree, 8 K idesc
  461.    LAYOUT: 1000 blk/trk; 1 trk/cyl; 1 cyl
  462.            1000 total blocks of 8 KB for 8192.000 KB
  463.    FREE: 0 free, 1000 used
  464.    BITMAP: 1 blk each, freemap @ 2, slotmap @ 4, filemap @ 5
  465.    UNIQUE: start @ 3
  466.    LOG: start @ 7, ctl blk @ 6, blk sz 8 K, #blks 993
  467.                 end of log @ dismount: LSN w=0.o=0, LRC w=0.c=1
  468. VOLID 8000, version 3, is a DATA volume
  469.    BLOCK SIZES: 8 K slotted, 8 K lg data,  8 K lg hdr
  470.            8 K btree, 8 K idesc
  471.    LAYOUT: 300 blk/trk; 1 trk/cyl; 1 cyl
  472.            300 total blocks of 8 KB for 2457.600 KB
  473.    FREE: 294 free, 6 used
  474.    BITMAP: 1 blk each, freemap @ 2, slotmap @ 4, filemap @ 5
  475.    UNIQUE: start @ 3
  476. \fR
  477. .)b
  478. .lp
  479. Now that you have formatted a log volume and a data volume,
  480. you are ready to start a server.
  481. .br
  482. .sh 3 "Configuring a Server"
  483. .lp
  484. Before you start a server, you need to create its configuration
  485. file.
  486. In the directory in which you expect to run the server, 
  487. create a file called \fC.sm_config\fR that looks something like this,
  488. with the appropriate substitutions (in particular,
  489. for each occurrence of \fC/path/to\fR below):
  490. .(b
  491. .nf
  492. \fC
  493. server*bufpages:    500
  494. # Portname need not be identical to log volume id.
  495. # This is just a convenience. 
  496. server*portname:    9000
  497. server*diskproc:    /path/to/diskrw
  498. server*logformat:    /path/to/logfile: 9000: 1: 1: 1000: 8
  499. server*dataformat:   /path/to/datafile: 8000: 1: 1: 500
  500. server*logvolume:    9000
  501. \fR
  502. .)b
  503. .lp
  504. If the same configuration file is to be used for the formatter
  505. and the server, the format options can be made to be recognized
  506. by both:
  507. .(b
  508. \fC
  509. [sf]*[rl].logformat: /path/to/logfile: 9000: 1: 1: 1000: 8
  510. [sf]*[rl].dataformat:/path/to/datafile: 8000: 1: 1: 500
  511. \fR
  512. .)b
  513. .lp
  514. Now you can start the server.
  515. Open a window in which to run the server, and, in the
  516. directory containing the server and its configuration
  517. file, start the server:
  518. .(b
  519. \fCsm_server\fR
  520. .)b
  521. The server is started on a newly formatted log volume, so
  522. it automatically regenerates the log. 
  523. The server prints
  524. .(b
  525. \fCServer is ready for requests.\fR
  526. .)b
  527. when it can serve applications. 
  528. .br
  529. .sh 3 "Compiling and Linking Your Application"
  530. .lp
  531. An application program must include the header file
  532. \fCsm_client.h\fR, which, in turn includes
  533. \fC<stdio.h>\fR, 
  534. \fC<setjmp.h>\fR, 
  535. \fC<sys/types.h>\fR, 
  536. \fC<netinet/in.h>\fR.
  537. Applications can be compiled with a C or C++ compiler.
  538. .lp
  539. The client library is compiled with C++,
  540. so client programs must be linked with a C++ compiler.
  541. See the \fIEXODUS Storage Manager Installation Manual\fR for 
  542. more information.
  543. .br
  544. .sh 3 "Configuring and Running Your Application"
  545. .lp
  546. The programs need configuration options to determine where
  547. to find the server that manages the data volumes they use,
  548. and to determine the sizes of the buffer pools they will use.
  549. In the directory in which you expect to run the application programs, 
  550. Create a file called \fC.sm_config\fR that looks something like this,
  551. with the appropriate substitutions:
  552. .(b
  553. .nf
  554. \fC
  555. # both producer and consumer will use 
  556. # 250 page buffer pools:
  557. client*bufpages:    250
  558. # substitute the name or Internet address
  559. # of the host on which the server runs:
  560. client*mount:    8000    9000@serverhost
  561. \fR
  562. .)b
  563. Now you can run the producer and the consumer.
  564. It is easiest to create a window in which to run each
  565. program.
  566. The produce and consumer programs use the environment
  567. variable EVOLID to determine the what volume to use.
  568. EVOLID must be set in each window.
  569. .lp
  570. In window P:
  571. .(b
  572. \fC# producer <name> <#objects> <object size>
  573. setenv EVOLID 8000
  574. producer P 100 1000\fR
  575. .)b
  576. In window C:
  577. .(b
  578. .sp 1
  579. \fC# consumer <name> <#objects> 
  580. setenv EVOLID 8000
  581. consumer C 100\fR
  582. .)b
  583. .lp
  584. The producer creates 
  585. \*(lq#objects\*(rq objects and 
  586. writes \*(lqname\*(rq in each one.  
  587. The \*(lqobject size\*(rq argument is the size of each object.
  588. The consumer reads and destroys
  589. \*(lq#objects\*(rq objects. 
  590. It prints the sizes of the objects and their names.
  591. The \*(lqname\*(rq given to the consumer program is
  592. immaterial, but is helpful for 
  593. reading the output
  594. when running more than one consumer.
  595. .lp
  596. The two programs use a single root entry and a single file on the
  597. given volume.
  598. When a consumer
  599. has consumed the last object in a file, it destroys the file and
  600. removes the root entry.  
  601. Each object is produced or consumed in a separate transaction.  
  602. When both a producer and
  603. consumer are running concurrently, 
  604. deadlocks occur periodically, 
  605. since both are reading and writing the same file.  
  606. When a deadlock occurs, 
  607. the offending program aborts its transaction and
  608. tries again.  
  609. Multiple producer and consumer programs may be started. 
  610. If the server fails or shuts down, the producer and consumer
  611. programs attempt to reconnect every five seconds, and when
  612. successful, they continue transaction processing.
  613. .br
  614. .sh 3 "Shutting Down the Server"
  615. .lp
  616. In the window in which the server runs,
  617. type the command:
  618. .(b
  619. \fCshutdown\fR
  620. .)b
  621. .lp
  622. The server prints various messages, among them
  623. .(b
  624. \fC
  625. Clean shutdown: no recovery required on any volumes.
  626. All disk processes  killed.
  627. \fR
  628. .)b
  629. when recovery is not required.
  630. .bp
  631. .sh 1 "CONFIGURATION OPTIONS AND CONFIGURATION FILES"
  632. .lp
  633. The client library, servers, and administrative
  634. programs use configuration options.
  635. All the options have a string name, a type, 
  636. a set of possible values, a default value, and a current value. 
  637. Client options can be set by a call to an application
  638. interface function or 
  639. by a line in a \fIconfiguration file\fR.  
  640. .(x z
  641. configuration options
  642. .)x \*($n
  643. .(x z
  644. configuration file
  645. .)x \*($n
  646. Server options can be set on the command line or by a line in the 
  647. server's configuration file.  
  648. .lp
  649. Configuration files are Unix files, and are similar in format 
  650. to the X Window system's resource files.  
  651. Each line in a configuration file is an 
  652. \fIoption command\fR or a 
  653. \fIcomment\fR.
  654. .lp
  655. A comment is a line that begins with \*(lq#\*(rq or with \*(lq!\*(rq.
  656. .lp
  657. An option command is a line containing an \fIoption
  658. descriptor\fR, white space, and a string representing a
  659. value to assign to the option.  
  660. An option descriptor consists of
  661. an \fIoption prefix\fR 
  662. followed immediately by an option name and a \*(lq:\*(rq.
  663. .lp
  664. The option prefix specifies the type and name of the program
  665. or programs for which the option is to be set.  
  666. The program type is one of 
  667. \*(lqclient\*(rq, \*(lqserver\*(rq, and \*(lqformatvol\*(rq.  
  668. The program name is usually the file
  669. name of the program, without its path
  670. (an application program can override this).
  671. The program type and program name are separated by \*(lq.\*(rq.  
  672. For example, the complete option descriptor for the option
  673. \*(lqbufpages\*(rq on the server named \fCserverA\fR is
  674. \fCserver.serverA.bufpages:\fR.  
  675. .lp
  676. Wild card characters are allowed in
  677. the program type and name.  
  678. The character \*(lq*\*(rq represents any portion of the prefix.  
  679. The \*(lq?\*(rq character represents any program type or any program name.  
  680. The expressions describing the program type and the program name 
  681. are parsed by a regular expression handler,
  682. so complex expressions can be used.
  683. See the manual page for regex(3).
  684. .lp
  685. The names of options can be abbreviated, 
  686. as long as the abbreviation unambiguously identifies a single option.  
  687. (This is also true for options appearing on command lines.)
  688. Program types and names may not be abbreviated.  
  689. Option name, program type, and program name matches are case-sensitive.
  690. .lp
  691. Configuration options of type Boolean
  692. can be set with the
  693. Boolean values TRUE or FALSE,
  694. or with the strings \*(lqyes\*(rq, \*(lqtrue\*(rq, \*(lqno\*(rq or \*(lqfalse\*(rq.  
  695. The strings may be abbreviated and are not case-sensitive.
  696. .lp
  697. Each setting of an option overrides any 
  698. previous value for that option.
  699. .lp
  700. Below, excerpts from configuration files illustrate
  701. ways to use the options.
  702. .(b I
  703. \fC
  704. # log volumes for two servers, whose executable
  705. # file names are serverA and serverB
  706. server.serverA.logvolume:        1000
  707. server.serverB.logvolume:        2000
  708. \fR
  709. .)b
  710. .(b I
  711. \fC
  712. # turn off progress printing for all servers
  713. server*progress:                no
  714. # or
  715. server.?.progress:                no
  716. \fR
  717. .)b
  718. .(b I
  719. \fC
  720. ! all servers and clients have a 1000 page buffer pool
  721. *bufpages:                    1000
  722. # The application foo uses a 500 page buffer pool.
  723. # (overriding the value of 1000, above)
  724. client.foo.bufpages:            500
  725. # Applications beginning with the letter g use 400 pages
  726. client.g*.bufpages:                400
  727. \fR
  728. .)b
  729. .bp
  730. .sh 1 "THE STORAGE MANAGER APPLICATION INTERFACE"
  731. .lp
  732. The Storage Manager's application interface consists of a set of functions,
  733. macros, and variables.
  734. The Storage Manager software release contains the header file
  735. \fCsm_client.h\fR,
  736. in which are found the definitions for the macros and
  737. types that appear in this document.
  738. Function prototypes for the the Storage 
  739. Manager functions are also found in \fCsm_client.h\fR.
  740. By convention, words that appear capitalized in the text 
  741. are either C-preprocessor macros, or C- or C++- defined types,
  742. Functions definitions appear in bold face in the text.
  743. The rest of this section is divided into sub-sections
  744. describing error handling, 
  745. initialization and shutdown, 
  746. transactions, 
  747. buffer management, 
  748. operations on objects,
  749. operations on versions,
  750. operations on files, 
  751. operations on indexes, 
  752. miscellaneous macros, and 
  753. administrative functions.   
  754. .br
  755. .sh 2 "Handling Errors"
  756. .lp
  757. Error handling is important to 
  758. users wishing to write robust client applications.  
  759. We discuss it first, since most Storage Manager functions return error codes.  
  760. Although this issue is complex, some of the burden is lightened by 
  761. the recovery facilities of the Storage Manager.  
  762. In this section we focus on error codes and error messages.
  763. .lp
  764. Almost all Storage Manager functions have integer return codes.  
  765. .(x z
  766. error return codes, sm_errno
  767. .)x \*($n
  768. .(x z
  769. sm_errno
  770. .)x \*($n
  771. All functions (except those used in printing error messages) return either
  772. esmNOERROR (zero), which represents success, or esmFAILURE (negative
  773. one), which represents an error.  
  774. When an error occurs, the global variable 
  775. sm_errno contains an error code. 
  776. A small positive error code is an error code returned by Unix,
  777. as defined in \fC<errno.h>\fR. 
  778. An error code greater than 65,536 is an error returned by
  779. the Storage Manager, as defined in \fCsm_client.h\fR.
  780. The Storage Manager error codes have symbolic 
  781. names (C preprocessor macros) that
  782. begin with \fIesm\fR.
  783. \fBThe value of sm_errno is not defined when
  784. the function returns esmNOERROR.\fR
  785. .lp
  786. Information about error codes can be obtained from the
  787. functions sm_Error(\ ), and sm_ErrorId(\ ),
  788. which are discussed below.
  789. .lp
  790. Some errors cause a message to be printed to 
  791. the file addressed by \fCsm_ErrorStream\fR.
  792. By default,
  793. .(x z
  794. default error file for messages
  795. .)x \*($n
  796. this file is the standard error file, stderr, as defined in 
  797. \fC<stdio.h>\fR,
  798. but the application can change it any time after the Storage
  799. Manager is initialized.
  800. .lp
  801. Errors differ in severity and have different side effects.
  802. The most severe errors are fatal and cause the application
  803. to exit (the client library calls \fIexit(3)\fR).
  804. When the application exits, the servers abort the transaction, 
  805. if a transaction is active. 
  806. Fatal errors are caused by internal software problems in the Storage Manager.  
  807. An example of a fatal error is esmMALLOCFAILED, which occurs when the entire
  808. data segment has been allocated by the application and client library,
  809. and the Storage Manager cannot proceed.
  810. .lp
  811. Less severe errors
  812. cause the transaction to be aborted, but leave the application running.
  813. When this happens, sm_errno is given the value esmTRANSABORTED,
  814. .(x z
  815. esmTRANSABORTED
  816. .)x \*($n
  817. .(x z
  818. transaction aborted
  819. .)x \*($n
  820. and the client library also sets the global variable \fCsm_reason\fR.
  821. .(x z
  822. sm_reason
  823. .)x \*($n
  824. .(x z
  825. error return codes, sm_reason
  826. .)x \*($n
  827. The range of values for \fCsm_reason\fR
  828. is the same as the range of values for sm_errno.
  829. (The value of \fCsm_reason\fR is meaningful only if
  830. sm_errno has the value esmTRANSABORTED, and it
  831. is unpredictable and meaningless otherwise.)
  832. When the server or the client library aborts a transaction and
  833. returns esmTRANSABORTED to the application, the transaction is
  834. only partially aborted.
  835. The application \fBmust\fR complete the termination of the transaction by
  836. calling sm_AbortTransaction(\ ) (described in the 
  837. Section 4.3.3, \fBTransaction Operations\fR).  
  838. .lp
  839. Less severe errors are generated by incorrect arguments to client
  840. interface functions or the lack of resources, such as buffer space.
  841. The application can correct the problem and retry the operation
  842. without aborting the transaction.
  843. .lp
  844. Finally, some error codes indicate conditions that are not errors
  845. at all, such as esmEMPTYFILE, which is returned when an empty file
  846. is read.
  847. .lp
  848. The following two functions can be used to 
  849. print more information about the error.
  850. .sp
  851. .(b L
  852. \fBchar *sm_Error (errorCode)
  853. int         errorCode;        /* error code returned by an sm function /*\fR
  854. .)b
  855. .(b L
  856. \fBchar *sm_ErrorId (errorCode)
  857. int         errorCode;        /* error code returned by an sm function /*\fR
  858. .)b
  859. .lp
  860. These are the only Storage Manager functions that do not return an integer.  
  861. When a client library function returns an error, 
  862. sm_Error(\ ) can be called by the application
  863. to get a string that provides a brief description of the error. 
  864. It also provides descriptions of Unix error codes.
  865. Sm_ErrorId(\ ) is used to return the string representation of
  866. the error code. 
  867. For example, the call sm_ErrorId(esmBADOID) returns the string \*(lqesmBADOID\*(rq, 
  868. and the call sm_Error(esmBADOID) returns the string \*(lqinvalid object id.\*(rq
  869. .lp
  870. If the client is disconnected from a server (by a server crash,
  871. network failure, etc.) the client library tries to reconnect
  872. to the server the next time it issues a request to the server.
  873. If the server in question is not available, 
  874. the Storage Manager returns an error such as esmSERVERDIED or
  875. a Unix error such as ECONNREFUSED.
  876. While the server in question is doing recovery after a restart, 
  877. esmTRANSDISABLED is returned.
  878. The server responds to requests when recovery is completed.
  879. .br
  880. .sh 2 "Initialization and Shutdown Operations"
  881. .lp
  882. Initialization and shutdown functions are used at the
  883. beginning and end of an application program, 
  884. but most of them can be called at any time.  
  885. The pertinent functions are
  886. sm_SetClientOption(\ ), 
  887. sm_GetClientOption(\ ), 
  888. sm_ParseCommandLine(\ ),
  889. sm_ReadConfigFile(\ ),
  890. sm_Initialize(\ ), 
  891. and
  892. sm_ShutDown(\ ).
  893. .lp
  894. Before initializing the Storage Manager client with sm_Initialize(\ ), 
  895. a number of client configuration options must be set by the application.
  896. .(x z
  897. configuration options
  898. .)x \*($n
  899. Options can be set through calls to sm_SetClientOption(\ ),
  900. sm_ParseCommandLine(\ ), or sm_ReadConfigFile(\ ).
  901. These options are summarized in Table 1.  
  902. See 
  903. Section 3 for information that applies to all options.
  904. .(b
  905. .TS
  906. box, center, tab(;);
  907. c|c|c|c|c
  908. c|c|c|c|c
  909. l|l|l|l|l.
  910. Option;Option;Possible;Default;Option
  911. Name;Type;Values;Values;Description
  912. _
  913. bufpages;int;> 4;none;# pages in the buffer pool
  914. groups;int;> 3;20;# buffer groups
  915. userdesc;int;> 0;2000;# user descriptors
  916. mount;string;volid port@host;none;where to find server
  917. ;;;;for this volume
  918. lognewpages;Boolean;yes,no,true,false;no/false;client logs new pages
  919. deallocpages;Boolean;yes,no,true,false;yes/true;removes empty pages 
  920. pagelock;string;SH,EX;SH;default lock for pages
  921. traceflags;int;>= 0;0;set tracing flags
  922. locktimeout;int;>= 0;30;# 10-second intervals
  923. ;;;;willing to await a lock
  924. .TE
  925. .ce
  926. .uh "Table 1: Client Options"
  927. .(x z
  928. options, client
  929. .)x \*($n
  930. .)b
  931. .lp
  932. The \*(lqbufpages\*(rq option
  933. sets the size of the client buffer pool in 8 Kbyte pages
  934. (or \fIn\fR byte pages, for \fIn\fR=MIN_PAGESIZE;
  935. MIN_PAGESIZE is defined in \fCsm_client.h\fR).
  936. See 
  937. Section 4.11.3, \fBTuning the Application\fR 
  938. for more information about setting this option.
  939. .lp
  940. The \*(lqgroups\*(rq option sets the limit on the number of buffer groups that can 
  941. be opened at once.  
  942. The default value is 20.
  943. See 
  944. Section 4.6, \fBBuffer Operations\fR,
  945. for more information about buffer groups.  
  946. .lp
  947. The \*(lquserdescs\*(rq option sets the limit on the number of open user descriptors.  
  948. The number of user descriptors should be set to the 
  949. maximum number of simultaneous object
  950. references that are expected by the application program.  
  951. The default value is 2000.
  952. See 
  953. Section 4.7, \fBOperations on Objects\fR,
  954. for more information about user descriptors.
  955. .lp
  956. The \*(lqlognewpages\*(rq option, if \*(lqyes\*(rq, causes the client to generate
  957. log pages for newly allocated pages, and if \*(lqno\*(rq, causes the
  958. server to generate the log pages.
  959. Setting this option to \*(lqno\*(rq results in fewer 
  960. log records shipped to servers and usually 
  961. lowers log space requirements for transactions that create objects.  
  962. With rare patterns of use, setting 
  963. \*(lqlognewpages\*(rq to \*(lqyes\*(rq results in better performance:
  964. if the objects that cause new pages to be allocated are small,
  965. and if enough work is done between object-creation operations to cause
  966. the newly allocated pages to be swapped,
  967. the preferred value for \*(lqlognewpages\*(rq is \*(lqyes\*(rq.
  968. In general, it is difficult to predict which objects will be 
  969. be created on newly allocated pages.
  970. The \*(lqlognewpages\*(rq option may be set only when a transaction is not active.
  971. .lp
  972. The \*(lqdeallocpages\*(rq option, if \*(lqyes\*(rq, causes the client to deallocate
  973. pages that become empty after objects are destroyed.
  974. If the option's value is \*(lqno\*(rq, these pages remain in the file,
  975. and do not get used again unless an appropriate \fInear-hint\fR 
  976. .(x z
  977. near-hint
  978. .)x \*($n
  979. .(x z
  980. hint, near-
  981. .)x \*($n
  982. is given when an object is subsequently created.
  983. Under most circumstances, the preferred value of \*(lqdeallocpages\*(rq
  984. is \*(lqyes\*(rq.
  985. If objects are created and destroyed in a LIFO fashion, and
  986. if the near-hint for object creation is NEAR_LAST, 
  987. the preferred  value is \*(lqno\*(rq.
  988. .lp
  989. The \*(lqpagelock\*(rq option changes the default
  990. lock mode for pages.
  991. See the 
  992. Section 4.2, \fBInitialization and Shutdown Operations\fR,
  993. and Appendix A, \fBLocking Protocol for Storage Manager Operations\fR
  994. for information about using options.
  995. .lp
  996. The \*(lqtraceflags\*(rq option is used to turn on tracing, and is only
  997. available in a Storage Manager that was compiled with -DDEBUG.
  998. The \*(lqtraceflags\*(rq option takes effect immediately and can be set at any time.  
  999. .lp
  1000. The \*(lqmount\*(rq options indicate the locations of the volumes that the
  1001. applications use.
  1002. The \*(lqmount\*(rq option may be used more than once, 
  1003. to \fIadd\fR new volumes to the 
  1004. client library's set of usable volumes,
  1005. or to \fIchange\fR the location of a volume.
  1006. The option value consists of a volume's integer identifier,
  1007. an Internet address, and a port at which
  1008. can be found a server that manages the volume.
  1009. The Internet addresses and port have format 
  1010. \fIport @ host\fR,
  1011. where both the port and the host can be numeric or symbolic.
  1012. Symbolic port names must be
  1013. found in the services database used by \fIgetservbyname(3n)\fR,
  1014. and symbolic host names must be in the
  1015. host name database used by \fIgethostbyname(3n)\fR.
  1016. The following example shows three values for the
  1017. \*(lqmount\*(rq option that
  1018. accomplish the same thing in three ways.
  1019. The volume 1000 is managed by the 
  1020. server listening on port 1152 
  1021. (which 
  1022. is called \*(lqbounty\*(rq in the \fC/etc/services\fR
  1023. database) on the local machine, 
  1024. whose Internet address is 128.105.2.153, also known as
  1025. \*(lqpitcairn.isle.edu\*(rq to the host-name server.
  1026. .(l
  1027.     \fC1000 1152@128.105.2.153\fR
  1028.     \fC1000 bounty@pitcairn.isle.edu\fR
  1029.     \fC1000 1152@pitcairn.isle.edu\fR.
  1030. and
  1031.     \fC1000 bounty@128.105.2.153\fR
  1032. .)l
  1033. .lp
  1034. The host name \fIlocalhost\fR \fBdoes not work\fR
  1035. if you are using distributed transactions (multiple
  1036. cooperating servers).
  1037. .lp
  1038. Volume identifiers \fBmust identify volumes
  1039. unambiguously, across all servers.\fR
  1040. .lp
  1041. For each application or client,
  1042. \fBall the host names used for a given server 
  1043. must resolve to the same Internet address\fR.
  1044. Using the above example,
  1045. this means that 
  1046. \*(lq128.105.2.153\*(rq
  1047. and
  1048. \*(lqpitcairn.isle.edu\*(rq
  1049. are interchangeable.
  1050. \*(lqLocalhost\*(rq, 
  1051. which resolves to the Internet address 127.0.0.1,
  1052. is not interchangeable with
  1053. \*(lq128.105.2.153\*(rq
  1054. or
  1055. \*(lqpitcairn.isle.edu\*(rq,
  1056. even though it addresses the same machine when
  1057. used by a client on 
  1058. \*(lqpitcairn.isle.edu\*(rq.
  1059. .lp
  1060. It is acceptable to use two \fIdifferent\fR servers running
  1061. on a machine, by addressing them at different \fIports\fR.
  1062. This means that
  1063. .(l
  1064.     \fC1000 1151@pitcairn.isle.edu\fR
  1065. and
  1066.     \fC2000 1152@pitcairn.isle.edu\fR
  1067. .)l
  1068. can serve an application.
  1069. .lp
  1070. The \*(lqlocktimeout\*(rq option
  1071. limits the  time the server waits to acquire a lock on behalf
  1072. of the client.
  1073. The value represents a number of 10-second intervals.
  1074. A value of zero means that the server does not wait at all,
  1075. and if the lock cannot be acquired immediately, the 
  1076. client operation returns esmFAILURE, with
  1077. esmLOCKBUSY in sm_errno.
  1078. The option value can be changed at any time.
  1079. The value that is in effect at the time a transaction 
  1080. makes its first request to a server
  1081. is the value used for lock requests on that server
  1082. for the duration of the transaction.
  1083. See Appendix A, 
  1084. Section A.3, \fBDeadlock Detection and Avoidance\fR,
  1085. for more information about locks.
  1086. See also 
  1087. Section 4.4, \fBMounting and Dismounting Volumes\fR,
  1088. for information concerning the protocol between clients and
  1089. servers.
  1090. .lp
  1091. To support code that was written before the configuration option
  1092. .(x z
  1093. configuration options
  1094. .)x \*($n
  1095. facility was added, the client library looks for the 
  1096. environment variable ESMCONFIG.  
  1097. If set, ESMCONFIG indicates a configuration file to read.  
  1098. .(x z
  1099. configuration file
  1100. .)x \*($n
  1101. The file is read using sm_ReadConfigFile(\ ),
  1102. with its \*(lqprogramName\*(rq argument having the value NULL.
  1103. It is read before any option is set, so all other functions that set 
  1104. options override those found in the ESMCONFIG file.
  1105. .sp
  1106. .(b L
  1107. \fBsm_SetClientOption (optionName, optionValue, valueType)
  1108. char        *optionName;    /* IN name of the option to set */
  1109. void        *optionValue;    /* IN new value for the option  */
  1110. SMDATATYPE    valueType;    /* IN type of optionValue */\fR
  1111. .)b
  1112. .(x z
  1113. sm_SetClientOption
  1114. .)x \*($n
  1115. Sm_SetClientOption(\ ) sets the option named \*(lqoptionName\*(rq to the
  1116. value in \*(lqoptionValue\*(rq.  
  1117. The \*(lqvalueType\*(rq arguments indicates the
  1118. type addressed by \*(lqoptionValue\*(rq.  
  1119. The supported types
  1120. are SM_int, SM_Boolean, and SM_string.  
  1121. If \*(lqvalueType\*(rq matches the type of the
  1122. option as specified in Table 1, a simple assignment is done.
  1123. If \*(lqvalueType\*(rq is SM_string and the option has a different type,
  1124. a conversion is performed.
  1125. .sp
  1126. .(b L
  1127. \fBsm_GetClientOption (optionName, optionValue)
  1128. char        *optionName;    /* IN name of the option to get */
  1129. void        *optionValue;    /* OUT value for the option  */\fR
  1130. .)b
  1131. .(x z
  1132. sm_GetClientOption
  1133. .)x \*($n
  1134. Sm_GetClientOption(\ ) retrieves the value for \*(lqoptionName\*(rq
  1135. and returns it in \*(lqoptionValue\*(rq.  It is assumed that the location 
  1136. addressed by \*(lqoptionValue\*(rq
  1137. matches the type, found in Table 1, for the option.  
  1138. For string-type options, the argument \*(lqoptionValue\*(rq is
  1139. treated as type \*(lqconst char **\(*rq.  That is, it should contain the
  1140. address of a pointer variable that is  updated to point to a
  1141. read-only buffer containing the option value.
  1142. .sp
  1143. .(b L
  1144. \fBsm_ParseCommandLine (argc, argv, errorMsg)
  1145. int        *argc;            /* IN/OUT number of command line arguments */
  1146. char        **argv;        /* IN/OUT command line arguments */
  1147. char        **errorMsg;        /* OUT syntax error message */\fR
  1148. .)b
  1149. .(x z
  1150. sm_ParseCommandLine
  1151. .)x \*($n
  1152. Sm_ParseCommandLine(\ ) searches the command line, \*(lqargv\*(rq, for any
  1153. client options.  Command-line options are
  1154. prefixed by a \*(lq-\*(rq.  The value for the option must follow the
  1155. option name.  
  1156. The Storage Manager ignores 
  1157. any command-line argument that is not recognized as a
  1158. Storage Manager client option.
  1159. If a client option is found, the name and value are removed 
  1160. from \*(lqargv\*(rq and \*(lqargc\*(rq is decremented by 2, even if there is 
  1161. an error in the option such as being given an illegal value.
  1162. If there is an error processing any option, \*(lqerrorMsg\*(rq is
  1163. changed to point to an error message string.
  1164. .sp
  1165. .(b L
  1166. \fBsm_ReadConfigFile (configFile, programName, errorMsg)
  1167. char        *configFile;        /* IN name of the configuration file */
  1168. char        *programName;    /* IN name of the application */
  1169. char        **errorMsg;        /* OUT syntax error message */\fR
  1170. .)b
  1171. .lp
  1172. Sm_ReadConfigFile(\ ) reads the option configuration file 
  1173. .(x z
  1174. sm_ReadConfigFile
  1175. .)x \*($n
  1176. \*(lqconfigFile\*(rq, and sets the options indicated.
  1177. If \*(lqconfigFile\*(rq is NULL, the default configuration
  1178. files \fC/usr/lib/exodus/sm_config\fR, \fC$HOME/.sm_config\fR, 
  1179. and \fC./.sm_config \fR are read in that order, if they exist.  
  1180. The name of the default configuration file \fC/usr/lib/exodus/sm_config\fR 
  1181. .(x z
  1182. default configuration files
  1183. .)x \*($n
  1184. .(x z
  1185. configuration files, default
  1186. .)x \*($n
  1187. can be changed 
  1188. with a minor Storage Manager source code change 
  1189. described in the installation manual, 
  1190. \fIEXODUS Storage Manager Installation Manual\fR.  
  1191. The \*(lqprogramName\*(rq option gives the program name for matching with 
  1192. options in the configuration file.  
  1193. If \*(lqprogramName\*(rq is NULL and a previous call to sm_ReadConfigFile(\ ) 
  1194. had a non-NULL \*(lqprogramName\*(rq, the previous \*(lqprogramName\*(rq is used.  
  1195. If no previous call was made and a \*(lqprogramName\*(rq is not given,
  1196. configuration file lines that contain a program name are not used;
  1197. only generic entries, such as \fCclient.bufpages: 1000\fR and
  1198. \fCclient*bufpages: 1000\fR are used.
  1199. .lp
  1200. When an error occurs while reading the file, an error message is
  1201. stored in \*(lqerrorMsg\*(rq and esmFAILURE is returned, as with other
  1202. Storage Manager functions.  
  1203. The \*(lqerrorMsg\*(rq is describes syntax related errors in the configuration file.
  1204. .lp
  1205. See 
  1206. Section 3 for information about the format of configuration files.
  1207. .sp
  1208. .(b L
  1209. \fBsm_Initialize (\ )
  1210. .)b
  1211. .(x z
  1212. sm_Initialize(\ )
  1213. .)x \*($n
  1214. Sm_Initialize(\ ) initializes the Storage Manager's  data structures.  
  1215. No Storage Manager functions except option and configuration file functions may be called
  1216. .(x z
  1217. configuration file
  1218. .)x \*($n
  1219. before sm_Initialize(\ ) is called.  
  1220. Options that do not have defaults 
  1221. must be set before sm_Initialize(\ ) is called, otherwise
  1222. esmFAILURE is returned, sm_errno is set to indicate what
  1223. the problem is.
  1224. .sp
  1225. .(b L
  1226. \fBsm_ShutDown (\ )\fR
  1227. .)b
  1228. Sm_ShutDown(\ ) 
  1229. .(x z
  1230. sm_ShutDown(\ )
  1231. .)x \*($n
  1232. closes all the open buffer groups and 
  1233. frees the memory allocated at run-time
  1234. by the client library.
  1235. Once the client library has been shut down, 
  1236. it can used again by calling sm_Initialize(\ ).
  1237. The client library loses track the information 
  1238. in the \*(lqmount\*(rq client options, so 
  1239. if sm_Initialize(\ ) is to be used again, the 
  1240. configuration files must be reread or the mount 
  1241. options must be reset with sm_SetClientOption(\ ).
  1242. .lp
  1243. Figure 2 shows a simple \*(lqhello world\*(rq application for the Storage
  1244. Manager.  
  1245. It sets configuration options, initializes the client library, 
  1246. .(x z
  1247. configuration options
  1248. .)x \*($n
  1249. and shuts down the client library.  
  1250. A more complete program would, begin transactions,
  1251. perform operations on objects, files, and indexes.  
  1252. More sample programs are included with the software release.
  1253. .(z I
  1254. .sz -3
  1255. \fC/*
  1256.  *  "Hello world" program: demonstrates initialization and shutdown.
  1257.  */
  1258. #include <stdlib.h>
  1259. #include "sm_client.h"
  1260.  
  1261. void ErrorCheck (int, char *);
  1262.  
  1263. main(int argc, char** argv) {
  1264.     int        e;
  1265.     char       *errorMsg;
  1266.  
  1267.     e = sm_ReadConfigFile(NULL, argv[0], &errorMsg);
  1268.     if (e != esmNOERROR) {
  1269.         fprintf(stderr, "Configuration file error: %s", errorMsg);
  1270.         ErrorCheck(e, "sm_ReadConfigFile");
  1271.         exit(0);
  1272.     }
  1273.     e = sm_ParseCommandLine(&argc, argv, &errorMsg);
  1274.     if (e != esmNOERROR) {
  1275.         fprintf(stderr, "Command line error: %s", errorMsg);
  1276.         ErrorCheck(e, "sm_ParseCommandLine");
  1277.         exit(0);
  1278.     }
  1279.  
  1280.     e = sm_Initialize(\ ); ErrorCheck(e, "sm_Initialize");
  1281.     printf("Hello world!");
  1282.     e = sm_ShutDown(\ ); ErrorCheck(e, "sm_ShutDown");
  1283. }
  1284.  
  1285. void ErrorCheck (int e, char *func) {
  1286.     if (e < 0) {
  1287.         fprintf(stderr, "Storage Manager error \e"%s\e" in %s", 
  1288.         sm_Error(sm_errno), func);
  1289.         exit(1);
  1290.     }
  1291. }\fR
  1292. .sz +3
  1293. .ce
  1294. .uh "Figure 2: Example Program"
  1295. .)z
  1296. .br
  1297. .sh 2 "Transactions"
  1298. .lp
  1299. The Storage Manager supports transactions, 
  1300. including concurrency control and recovery.  
  1301. Transactions may involve data managed by several Exodus Storage Manager
  1302. servers, in which case a two-phase commit protocol, based on 
  1303. .(x z
  1304. presumed abort
  1305. .)x \*($n
  1306. Presumed Abort [Moha83], 
  1307. determines the fate of the transaction when the 
  1308. application commits the transaction.
  1309. The fact that such a transaction is distributed over several servers
  1310. .(x z
  1311. transactions, distributed
  1312. .)x \*($n
  1313. .(x z
  1314. distributed transactions
  1315. .)x \*($n
  1316. is invisible to the application.
  1317. On the other hand,
  1318. the Storage Manager (server or servers)
  1319. can cooperate in a two-phase commit procedure
  1320. with other transaction processing systems when the 
  1321. external two-phase commit functions are used.
  1322. The external two-phase commit functions also can be used explicitly
  1323. to invoke the two phases for a transaction
  1324. that involves only Exodus Storage manager servers.
  1325. The external two-phase commit functions are described 
  1326. under \*(lqAdvanced Topics\*(rq, in 
  1327. Section 4.11.3, \fBExternal Two-Phase Commit Functions\fR,
  1328. .lp
  1329. Object, file, index, and 
  1330. root entry operations must be performed within the scope of a
  1331. transaction, or an error is returned.  
  1332. An application can run no more than one transaction at a time.
  1333. Transactions cannot be nested, suspended, or resumed. 
  1334. .lp
  1335. In order to guarantee the semantics of transactions,
  1336. operations on objects and files acquire \fIlocks\fR.
  1337. .(x z
  1338. locks
  1339. .)x \*($n
  1340. Appendix A describes the kinds of locks acquired by 
  1341. the client library functions.
  1342. .br
  1343. .sh 3 "Transaction Identifiers"
  1344. .lp
  1345. Each transaction has a local transaction identifier, which is
  1346. assigned by the Storage Manager.
  1347. The data type TID represents a transaction identifier.
  1348. .(x z
  1349. transaction identifier
  1350. .)x \*($n
  1351. .(x z
  1352. transaction identifier, local
  1353. .)x \*($n
  1354. The application can treat a TID as an opaque value.
  1355. The Storage Manager maintains a global variable, Tid, of type TID,
  1356. which value the application can inspect, but had better not modify.
  1357. .lp
  1358. The application can use the following two macros 
  1359. to give an initial value
  1360. to a transaction identifier,
  1361. and to recognize that value.
  1362. .(b I
  1363. \fBINVALIDATE_TID (TID tid)\fR 
  1364. .)b
  1365. .lp
  1366. sets the \*(lqtid\*(rq argument to an invalid transaction identifier.
  1367. .(b I
  1368. \fBTID_IS_INVALID (TID tid)\fR 
  1369. .)b
  1370. .lp
  1371. returns TRUE if \*(lqtid\*(rq is the value given by
  1372. INVALIDATE_TID(\ ), FALSE if not.
  1373. TID_IS_INVALID(\ ) does not tell if there is an active transaction
  1374. with the given transaction identifier.
  1375. .br
  1376. .sh 3 "Transaction States"
  1377. .lp
  1378. An application is always in one the following states:
  1379. not running a transaction (INACTIVE), 
  1380. running a transaction (ACTIVE),
  1381. running a transaction that has been (partially) aborted (ABORTED).
  1382. .lp
  1383. An application is in the INACTIVE state until it calls
  1384. sm_BeginTransaction(\ ), and
  1385. after a call to sm_CommitTransaction(\ ) or sm_AbortTransaction(\ ).
  1386. .lp
  1387. If the Storage Manager server or client library aborts a transaction, 
  1388. which sometimes happens because of an error on the part of the application, 
  1389. the application is in the ABORTED state until a call to sm_AbortTransaction(\ ).
  1390. While in the ABORTED state, a call to any function other than sm_AbortTransaction(\ )  returns the 
  1391. .(x z
  1392. esmTRANSABORTED
  1393. .)x \*($n
  1394. error esmTRANSABORTED.
  1395. .br
  1396. .sh 3 "Transaction Operations"
  1397. .sp
  1398. .(b L
  1399. \fBsm_BeginTransaction (tid)
  1400. TID        *tid;            /* OUT transaction ID */\fR
  1401. .)b
  1402. .(x z
  1403. sm_BeginTransaction(\ )
  1404. .)x \*($n
  1405. Sm_BeginTransaction(\ ) is called at the beginning of a transaction.
  1406. The argument \*(lqtid\*(rq corresponds to a transaction identifier and is
  1407. assigned by the Storage Manager.
  1408. .lp
  1409. Sm_BeginTransaction(\ ) \fBdoes not\fR
  1410. contact any servers or
  1411. initiate a transaction with any server,
  1412. since the operation has no arguments to indicate
  1413. which servers are of interest.
  1414. It only begins a transaction 
  1415. \*(lqlocally\*(rq.
  1416. Once a transaction has begun locally,
  1417. the client library initiates transactions
  1418. on servers when data references so require.
  1419. .sp
  1420. .(b L
  1421. \fBsm_CommitTransaction (tid)
  1422. TID        tid;            /* IN transaction ID */\fR
  1423. .)b
  1424. .(x z
  1425. sm_CommitTransaction(\ )
  1426. .)x \*($n
  1427. Sm_CommitTransaction(\ ) is called to commit the effects of a
  1428. transaction.  
  1429. If the commit
  1430. succeeds, all changes made to data since the beginning of the
  1431. transaction are guaranteed to be persistent, 
  1432. even in the event of system failure.  
  1433. See 
  1434. Section 4.9.1, \fBConsistency Guarantees for Files\fR,
  1435. for more information about this guarantee.  
  1436. If the commit fails, an error is returned, and the
  1437. transaction is aborted.  
  1438. When a transaction is committed, all user descriptors (see sm_ReadObject(\ ) ) 
  1439. are released. 
  1440. Buffer groups attached to the transaction 
  1441. (see sm_OpenBufferGroup(\ ) ) are closed.
  1442. .sp
  1443. .(b L
  1444. \fBsm_AbortTransaction (tid)
  1445. TID        tid;            /* IN transaction ID */\fR
  1446. .)b
  1447. .(x z
  1448. sm_AbortTransaction(\ )
  1449. .)x \*($n
  1450. Sm_AbortTransaction(\ ) aborts a transaction.  
  1451. Sm_AbortTransaction(\ ) releases 
  1452. all the user descriptors that were created during
  1453. the transaction (see sm_ReadObject(\ ) ).
  1454. Buffer groups attached to the 
  1455. transaction (see sm_OpenBufferGroup(\ ) ) are closed.  
  1456. .lp
  1457. The persistent data appear as if the transaction never began.
  1458. The execution state of the application program is not affected 
  1459. by calling sm_AbortTransaction(\ ).
  1460. The result is that the transient data in the program's address
  1461. space do not match the state of the persistent data.
  1462. The problem can be alleviated to some degree by judicious
  1463. use of \fIsetjmp(2)\fR, \fIlongjmp(2)\fR, and lexical scoping
  1464. in the application program.
  1465. The following macros, which are defined in \fCsm_client.h\fR,
  1466. do that:
  1467. .sp
  1468. .(b L
  1469. \fBSM_BEGIN_TRANSACTION (tid, abortCode)
  1470. TID        *tid;            /* transaction ID */
  1471. int        abortCode;        /* location to store abort code */\fR
  1472. .)b
  1473. SM_BEGIN_TRANSACTION begins a transaction block (i.e. it opens a
  1474. new lexical scope in C or C++).  The transaction
  1475. ID is placed in \*(lqtid\*(rq.  The argument \*(lqabortCode\*(rq \fBmust\fR be a
  1476. variable.  This variable can be checked at the end of the transaction
  1477. to determined if it was aborted.
  1478. .sp
  1479. .(b L
  1480. \fBSM_COMMIT_TRANSACTION (tid)
  1481. TID        tid;            /* transaction ID */\fR
  1482. .)b
  1483. SM_COMMIT_TRANSACTION ends a transaction block.  
  1484. When this statement is executed, the transaction is committed,
  1485. assuming no error occurs during commit.  
  1486. Immediately after the SM_COMMIT_TRANSACTION statement, the \*(lqabortCode\*(rq variable given
  1487. in the SM_BEGIN_TRANSACTION statement should be checked to see
  1488. if any error occurred.  
  1489. If no error occurred, \*(lqabortCode\*(rq is set to esmNOERROR.  
  1490. Otherwise, \*(lqabortCode\*(rq is set to the value given in SM_ABORT_TRANSACTION.
  1491. .sp
  1492. .(b L
  1493. \fBSM_ABORT_TRANSACTION (abortCode)
  1494. int        abortCode;        /* error to return on abort */\fR
  1495. .)b
  1496. SM_ABORT_TRANSACTION aborts the active transaction 
  1497. (i.e.  sm_AbortTransaction(\ ) is called) 
  1498. and resumes execution at the line 
  1499. immediately following the SM_COMMIT_TRANSACTION statement for the transaction.  
  1500. The SM_ABORT_TRANSACTION macro does not need to be called within the
  1501. lexical scope of the transaction block.  
  1502. It can be called in any function operating in 
  1503. the dynamic scope of the transaction.
  1504. The \*(lqabortCode\*(rq argument sets the \*(lqabortCode\*(rq variable
  1505. given in SM_BEGIN_TRANSACTION. 
  1506. .lp
  1507. When a SM_ABORT_TRANSACTION is called, the program's control is 
  1508. transferred to the program point after the SM_COMMIT_TRANSACTION statement.  
  1509. The stack pointer is restored to the level of the transaction block, 
  1510. so functions on the program's stack after it are not completed.  
  1511. \fBFor C++, this means that destructors are not called for any local variables 
  1512. in those functions.\fR
  1513. .lp
  1514. Examples of using both the transaction macros and functions can
  1515. be found in the producer-consumer example given in the
  1516. Storage Manager software release.
  1517. .br
  1518. .sh 2 "Mounting and Dismounting Volumes"
  1519. .lp
  1520. An application program \fBdoes not\fR need to mount and
  1521. dismount volumes explicitly. 
  1522. In most cases,
  1523. the client library automatically mounts a volume
  1524. when the application makes its first reference to that volume.
  1525. An application that does not explicitly mount a volume
  1526. may, when it
  1527. performs its first operation on an object,
  1528. find that the server for that object is not
  1529. running.
  1530. Writing programs to handle such
  1531. common errors can be difficult, 
  1532. so it may be more convenient to
  1533. mount volumes before proceeding with
  1534. operations on data.
  1535. Sm_MountVolume(\ ) serves that purpose.
  1536. If that server 
  1537. has not yet been contacted, sm_MountVolume(\ )
  1538. establishes a connection to the server and mounts
  1539. the volume.
  1540. It does not begin a transaction.
  1541. (See Section 4.3.3, \fBTransaction Operations\fR to
  1542. understand how transactions are begun.)
  1543. .lp
  1544. When an application exits or calls sm_ShutDown(\ ),
  1545. connections to servers are severed, and the servers
  1546. dismount the volumes used by the application.
  1547. A server severs its connections and dismounts the
  1548. volumes if an application is \fIinactive\fR for 
  1549. a significant time.
  1550. An application is inactive if it has no transaction running.
  1551. .lp
  1552. An application can dismount volumes explicitly,
  1553. causing the volumes to be dismounted at the server.
  1554. An application that continues to run after it is
  1555. finished using the Storage Manager would do well
  1556. to use sm_ShutDown(\ ).
  1557. If it is inappropriate to use sm_ShutDown(\ ),
  1558. but such an application is finished with 
  1559. a set of volumes, it would do best to 
  1560. dismount the volumes,
  1561. particularly if the volumes are likely
  1562. to be reformatted. 
  1563. .sp
  1564. .(b L
  1565. \fBsm_MountVolume ( volid )
  1566. VOLID    volid;            /* IN volume to mount */
  1567. .)b
  1568. .(x z
  1569. sm_MountVolume(\ )
  1570. .)x \*($n
  1571. .lp
  1572. Sm_MountVolume(\ ) causes the volume identified
  1573. by \*(lqvolid\*(rq to be mounted.
  1574. A side effect of the operation is that the
  1575. client library has established a connection with
  1576. the server that manages this volume.
  1577. .lp
  1578. If the volume cannot be mounted, sm_MountVolume(\ ) returns
  1579. esmFAILURE and a value in sm_errno that describes the reason:
  1580. esmNOSUCHVOLUME (the client library cannot identify
  1581. the server for this volume because there is no \*(lqmount\*(rq
  1582. option for this volid),
  1583. esmTRANSABORTED (the transaction was aborted during the previous
  1584. operation, and the next thing the application must do is
  1585. abort the transaction),
  1586. esmSERVERDIED (connection with server was severed during the
  1587. mount operation),
  1588. or any Unix error message from \fC<errno.h>\fR (such
  1589. as ENETDOWN and ECONNREFUSED), which indicate that
  1590. the server is not running or is unreachable through the network.
  1591. .sp
  1592. .(b L
  1593. \fBsm_DismountVolume ( volid )
  1594. VOLID    volid;            /* IN volume to dismount */
  1595. .)b
  1596. .(x z
  1597. sm_DismountVolume(\ )
  1598. .)x \*($n
  1599. .lp
  1600. The \*(lqvolid\*(rq argument identifies the volume
  1601. to be dismounted.
  1602. If the volume is not mounted, the operation
  1603. returns esmFAILURE, and 
  1604. the client library returns esmBADVOLID in sm_errno. 
  1605. .sh 2 "Root Entries"
  1606. .lp
  1607. The root entry facility is designed for applications to get a handle 
  1608. to data on a volume.  \**
  1609. .(f
  1610. \** Root entries cannot be created on temporary volumes.
  1611. .)f
  1612. A common use of a root entry is to associate a string name with 
  1613. an object identifier for an object containing information about 
  1614. the contents of the volume.  
  1615. For example, in a database system, this might be the
  1616. object identifier for the catalog.
  1617. .lp
  1618. A root entry is a string and data pair stored in a special location on a 
  1619. volume, called the root area.  
  1620. The string, called the name, is used to identify the entry.  
  1621. The name string must be null-terminated.  
  1622. The maximum lengths of the name (including the terminating null)
  1623. and data are defined by 
  1624. MAX_ROOTNAME_SIZE and MAX_ROOTDATA_SIZE respectively.  
  1625. An error is returned if the available number of root entries is exceeded.  
  1626. Names and data are limited to 32 bytes each,
  1627. and approximately 90 root entries can reside in a volume's root area.
  1628. .sp
  1629. .(b L
  1630. \fBsm_SetRootEntry (volid, name, data, dataLength)
  1631. VOLID    volid;            /* IN volume identifier */
  1632. char        *name;        /* IN name to store data entry under */
  1633. void        *data;            /* IN data entry to be stored */
  1634. int        dataLength;        /* IN length of the data */
  1635. .)b
  1636. .(x z
  1637. sm_SetRootEntry(\ )
  1638. .)x \*($n
  1639. .lp
  1640. Sm_SetRootEntry(\ ) is creates or updates an entry.  
  1641. The \*(lqname\*(rq argument is the name of the entry and the \*(lqdata\*(rq 
  1642. argument is the data to be stored.  
  1643. The number of bytes in the data is given in \*(lqdataLength\*(rq.  
  1644. For example, to store
  1645. the contents of the variable \*(lqrootOid\*(rq under the name \*(lqroot-obj\*(rq, use
  1646. \fCsm_SetRootEntry(volid, 
  1647. \*(lqroot-obj\*(rq, (char*) &rootOid, sizeof(rootOid))\fR.
  1648. .lp
  1649. Sm_SetRootEntry(\ ) obtains an exclusive
  1650. .(x z
  1651. lock, exclusive
  1652. .)x \*($n
  1653. lock on the root area of the volume, so 
  1654. updates to root entries should be performed in a short transaction.
  1655. .sp
  1656. .(b L
  1657. \fBsm_GetRootEntry (volid, name, data, dataLength)
  1658. VOLID    volid;            /* IN volume identifier */
  1659. char        *name;        /* IN name of the entry */
  1660. void        *data;            /* OUT data stored under name */
  1661. int         *dataLength;        /* IN/OUT length of the data */
  1662. .)b
  1663. .(x z
  1664. sm_GetRootEntry(\ )
  1665. .)x \*($n
  1666. Sm_GetRootEntry(\ ) retrieves the root entry named \*(lqname\*(rq.  The data is
  1667. placed in \*(lqdata\*(rq and the length of the data is returned in
  1668. \*(lqdataLength\*(rq.  If \*(lqdataLength\*(rq is initialized with a value greater than
  1669. or equal to zero, the maximum number of bytes copied to \*(lqdata\*(rq
  1670. is \*(lqdataLength\*(rq.  If \*(lqdataLength\*(rq is initialized with a value less
  1671. than zero, the entire length of the data is copied to \*(lqdata\*(rq.  
  1672. .lp
  1673. Sm_GetRootEntry(\ ) obtains a share lock on the root area of the volume.  
  1674. This share lock blocks other 
  1675. .(x z
  1676. lock, share
  1677. .)x \*($n
  1678. transactions from updating or removing root entries
  1679. until the transaction is committed or aborted.  
  1680. If no root entry exists for \*(lqname\*(rq, esmFAILURE 
  1681. is returned and sm_errno is set to esmBADROOTNAME.
  1682. .sp
  1683. .(b L
  1684. \fBsm_RemoveRootEntry (volid, name)
  1685. VOLID    volid;            /* IN volume identifier */
  1686. char        *name;        /* IN name of entry */
  1687. .)b
  1688. .(x z
  1689. sm_RemoveRootEntry(\ )
  1690. .)x \*($n
  1691. .lp
  1692. Sm_RemoveRootEntry(\ ) removes the root entry stored under \*(lqname\*(rq.
  1693. Sm_RemoveRootEntry(\ ) obtains an exclusive
  1694. .(x z
  1695. lock, exclusive
  1696. .)x \*($n
  1697. lock on the root area of the volume, so 
  1698. removal of root entries should be performed in a short transaction.
  1699. .br
  1700. .sh 2 "Buffer Operations"
  1701. .lp
  1702. The Storage Manager buffer manager implements the concept of a
  1703. \fIbuffer group\fR, as proposed in the DBMIN buffer management
  1704. .(x z
  1705. buffer group
  1706. .)x \*($n
  1707. algorithm [Chou85].  
  1708. The essence of the DBMIN algorithm is that 
  1709. competing uses of the buffer pool may be 
  1710. allocated their own buffers, to minimize competition for 
  1711. the buffers and to eliminate thrashing in the buffer pool.
  1712. .lp
  1713. All uses of the buffer pool are made through a buffer group.
  1714. A buffer group is a container of page buffers, with a limit
  1715. on the number of \fIfixed\fR pages it can contain.
  1716. .(x z
  1717. pages, fixed
  1718. .)x \*($n
  1719. .(x z
  1720. fixed pages
  1721. .)x \*($n
  1722. Fixed pages are guaranteed to remain in the buffer pool
  1723. until they are \fIunfixed\fR. 
  1724. .(x z
  1725. unfixed pages
  1726. .)x \*($n
  1727. .(x z
  1728. pages, unfixed
  1729. .)x \*($n
  1730. Their locations (virtual addresses) may change, but 
  1731. the pages remain in the virtual address space
  1732. of the buffer pool.
  1733. Each buffer group has a replacement policy, which
  1734. controls the replacement of unfixed pages within the buffer group.
  1735. .lp
  1736. Buffer groups can be opened and closed at any time,
  1737. whether or not a transaction is running.
  1738. If a buffer group is opened in a transaction, it may be 
  1739. \*(lqattached\*(rq to the transaction, which means that the
  1740. buffer group is closed by the client library
  1741. when the transaction ends.
  1742. An attached buffer group can be closed explicitly 
  1743. by the application before the transaction ends.
  1744. .lp
  1745. The following two macros can be used with buffer
  1746. groups 
  1747. to give an initial value
  1748. to a buffer group index
  1749. and to recognize that value.
  1750. .(b I
  1751. \fBINVALIDATE_BUFGROUP (int bufgroup)\fR 
  1752. .)b
  1753. .lp
  1754. sets the \*(lqbufgroup\*(rq argument to an invalid buffer group index.
  1755. .(b I
  1756. \fBBUFGROUP_IS_INVALID (int bufgroup)\fR 
  1757. .)b
  1758. .lp
  1759. returns TRUE if \*(lqbufgroup\*(rq is the value given by
  1760. INVALIDATE_BUFGROUP(\ ), FALSE if it is not.
  1761. BUFGROUP_IS_INVALID(\ ) does not tell if there exists a
  1762. buffer group with the given index.
  1763. .sp
  1764. .(b L
  1765. \fBsm_OpenBufferGroup (groupSize, policy, groupIndex, flags)
  1766. int        groupSize;        /* IN the maximum group size in pages */
  1767. int        policy;            /* IN the group's replacement policy */
  1768. int        *groupIndex;        /* OUT the group's index */
  1769. FLAGS     flags;            /* IN buffer group attributes */\fR
  1770. .)b
  1771. .(x z
  1772. sm_OpenBufferGroup(\ )
  1773. .)x \*($n
  1774. .lp
  1775. Sm_OpenBufferGroup(\ ) opens a new buffer group.
  1776. The \*(lqgroupSize\*(rq argument specifies the size of the buffer group
  1777. in MIN_PAGESIZE pages.  
  1778. The sum of the sizes of all
  1779. open buffer groups cannot exceed the size of the buffer pool.
  1780. (See 
  1781. Section 4.11.3, \fBTuning the Application\fR.)
  1782. The choice for \*(lqpolicy\*(rq is  
  1783. least-recently-used (BF_LRU)
  1784. or 
  1785. most-recently-used (BF_MRU).
  1786. BF_LRU and BF_MRU are defined in \fCsm_client.h\fR.
  1787. The argument \*(lqgroupIndex\*(rq is filled by the Storage Manager and must be
  1788. used in subsequent references to the buffer group.
  1789. (All operations on files and objects require a buffer group index.)
  1790. .lp
  1791. The \*(lqflags\*(rq indicates whether the buffer group is to be associated with 
  1792. a transaction.
  1793. NOFLAGS indicates that it is not.
  1794. TRANS_GROUP indicates that the buffer group is associated with the
  1795. current transaction. 
  1796. The group is closed by the client library
  1797. when the active transaction ends. 
  1798. If TRANS_GROUP is used, a transaction must be running
  1799. at the time sm_OpenBufferGroup(\ ) is called.
  1800. .lp
  1801. The effect of sm_OpenBufferGroup(\ ) is to reserve \*(lqgroupSize\*(rq
  1802. pages in the client's buffer pool. No buffer group is opened on the
  1803. server.
  1804. .sp
  1805. .(b L
  1806. \fBsm_BufferGroupInfo (groupIndex, maxPages, fixedPages, unfixedPages)
  1807. int        groupIndex;        /* IN the group to inspect */
  1808. int        *maxPages;        /* OUT max fixed pages allowed      */
  1809. int        *fixedPages;        /* OUT current # of pages fixed     */
  1810. int        *unfixedPages;    /* OUT current # of pages unfixed   */\fR
  1811. .)b
  1812. .(x z
  1813. sm_BufferGroupInfo(\ )
  1814. .)x \*($n
  1815. .lp
  1816. Sm_BufferGroupInfo(\ ) returns information about the open buffer group
  1817. identified by \*(lqgroupIndex\*(rq.
  1818. The function returns the buffer group's size limit in pages
  1819. in \*(lqmaxPages\*(rq.
  1820. In \*(lqfixedPages\*(rq, it 
  1821. returns the number of pages currently fixed in the buffer group.
  1822. See the next section for more information about these functions.
  1823. The argument \*(lqunfixedPages\*(rq refers to all buffer pages that
  1824. belong to the buffer group, but are not fixed, that is these pages
  1825. may be removed from the buffer pool if space is needed for fixed
  1826. pages.
  1827. .sp
  1828. .(b L
  1829. \fBsm_CloseBufferGroup (groupIndex)
  1830. int        groupIndex;        /* IN the group being closed */\fR
  1831. .)b
  1832. .(x z
  1833. sm_CloseBufferGroup(\ )
  1834. .)x \*($n
  1835. Sm_CloseBufferGroup(\ ) closes the open buffer group
  1836. identified by \*(lqgroupIndex\*(rq.
  1837. \" **********************************************************************
  1838. .br
  1839. .sh 2 "Operations on Objects"
  1840. .lp
  1841. An object in the Storage Manager is a container of bytes. 
  1842. It can be empty.
  1843. It can have as many as 2\*[31\*] bytes, if the volume on which
  1844. it resides is large enough.
  1845. An object must fit on a single volume (storage device or partition).
  1846. When an object is created, 
  1847. the Storage Manager gives the object a unique object identifier.
  1848. An object identifier is described by
  1849. a structure of the type OID, defined as follows:. 
  1850. .(b I
  1851. \fBtypedef struct {
  1852.        SHORTPID    pid;            /* 32-bit page address of the object's header */
  1853.        SLOTINDEX    slot;        /* 16-bit slot number of the object on the page */
  1854.        VOLID         volid;        /* 16-bit identifier of the volume */
  1855.        UNIQUE        unique;    /* 32-bit number generated at creation time */
  1856. } OID; \fR
  1857. .(x z
  1858. OID
  1859. .)x \*($n
  1860. .)b
  1861. .lp
  1862. The first three fields of an OID are the physical address of the object;
  1863. they identify a volume, 
  1864. a page within the volume, 
  1865. and a \fIslot\fR on the page.
  1866. .(x z
  1867. slot
  1868. .)x \*($n
  1869. An object's identifier never changes. 
  1870. The client library sometimes moves objects, such as when
  1871. an object grows beyond the size of a page, at which time the
  1872. object is marked as \fIforwarded\fR, but its OID remains
  1873. .(x z
  1874. forwarded object
  1875. .)x \*($n
  1876. unchanged.
  1877. .lp
  1878. The \*(lqunique\*(rq field of an OID is special 32-bit value that is generated
  1879. when the object is created and used to detect dangling and corrupted
  1880. OIDs.
  1881. The generation of unique numbers is discussed in Appendix B.
  1882. .lp
  1883. Every time an object is accessed by its OID,
  1884. the Storage Manager validates the OID.
  1885. The application can use the following macros to
  1886. give an illegitimate initial value to an OID,
  1887. and to recognize that value:
  1888. .(b I
  1889. \fBINVALIDATE_OID (OID oid)\fR 
  1890. .)b
  1891. sets the \*(lqoid\*(rq argument to an invalid object identifier.
  1892. .(b I
  1893. \fBOID_IS_INVALID (OID oid)\fR
  1894. .)b
  1895. returns TRUE if \*(lqoid\*(rq is the value given by INVALIDATE_OID(\ ),
  1896. FALSE if it is not.
  1897. .lp
  1898. Each object has an \fIobject header\fR, which describes the object,
  1899. .(x z
  1900. object header
  1901. .)x \*($n
  1902. and which can be retrieved without retrieving the object's data.
  1903. The structure of an object header is shown below:
  1904. .(b I
  1905. \fBtypedef struct {
  1906.        TWO    properties;    /* a bit vector */
  1907.        TWO    tag;        /* supplied by the application */
  1908.        int        size;        /* size of the object in bytes */
  1909. } OBJHDR;\fR
  1910. .(x z
  1911. OBJHDR
  1912. .)x \*($n
  1913. .(x z
  1914. object header
  1915. .)x \*($n
  1916. .)b
  1917. .lp
  1918. The \*(lqtag\*(rq is a two-byte field that the Storage Manager does not interpret.
  1919. It is for use by the application.
  1920. No restriction is put on the contents of \*(lqtag\*(rq fields.
  1921. As its name implies, the \*(lqsize\*(rq field is the size of the object in bytes.
  1922. The \*(lqproperties\*(rq field is a read-only bit-vector that indicates the
  1923. presence or absence of the following properties of objects:
  1924. .(b I
  1925. .ip "      P_LARGEOBJ" 23
  1926. set if the object is a large object.
  1927. .ip "      P_MOVED" 23
  1928. set if this object has been forwarded to another page.
  1929. .ip "      P_FROZEN" 23
  1930. set if the object is a frozen version.
  1931. .ip "      P_VERSIONED" 23
  1932. set if the object is a frozen version or a descendent of a frozen version.
  1933. .)b
  1934. .lp
  1935. Each object resides in a \fIfile\fR on a \fIvolume\fR.
  1936. .(x z
  1937. file
  1938. .)x \*($n
  1939. .(x z
  1940. volume
  1941. .)x \*($n
  1942. When an object is created, the application tells the client
  1943. library in which file to place the object.
  1944. Files and their uses are discussed in the next section;
  1945. details of their use are not pertinent to understanding 
  1946. the operations on objects.
  1947. .lp
  1948. Before an operation can be performed on an existing object,
  1949. the object, or at least the affected parts of the object, 
  1950. must be brought into the application's address space.
  1951. This is called \fIpinning\fR the object or its parts.
  1952. .(x z
  1953. pin
  1954. .)x \*($n
  1955. When the object is no longer needed, it must be \fIunpinned\fR,
  1956. .(x z
  1957. unpin
  1958. .)x \*($n
  1959. to make room for other objects to be pinned\**.
  1960. .(f
  1961. \** Objects are pinned; pages are fixed.  The gist of the two verbs is the same.
  1962. .)f
  1963. When the client library pins and object in order to perform
  1964. an operation on behalf of the application (for example,
  1965. appending bytes to an object), the client library pins the necessary
  1966. parts of the object and unpins them before it returns control
  1967. to the application.
  1968. When the application
  1969. pins part of an object for its own purposes (such as writing over
  1970. bytes in the object), the pinned part is placed in the client's buffer 
  1971. pool, and 
  1972. the client library creates a \*(lqhandle\*(rq for the
  1973. the object.  
  1974. The handle is called a \fIuser descriptor\fR.
  1975. The application can refer to an object only through user descriptors.
  1976. The application must unpin the object by \fIreleasing\fR
  1977. the user descriptor when it is done using the object.
  1978. .lp
  1979. A user descriptor is called \fIvalid\fR if and only 
  1980. if the byte range it addresses is pinned.
  1981. An application can pin an object or overlapping parts of an object
  1982. any number of times, having any number of valid user descriptors
  1983. for the same data in an object.
  1984. (This is not wise for performance reasons, but it can be done.)
  1985. .lp
  1986. The client library functions that pin ranges of bytes
  1987. return user descriptors to describe the bytes pinned.
  1988. Functions that require that the range of bytes they affect be pinned 
  1989. take user descriptors as input arguments.
  1990. The client library functions that do not take user descriptor
  1991. arguments do not ultimately change the quantity of bytes pinned
  1992. or the number of pages fixed in the buffer pool.  
  1993. \fBSuch functions  may change the ranges of bytes addressed or the
  1994. bytes themselves, but they do not change the quantity of bytes
  1995. addressed.\fR
  1996. (For example, the function sm_InsertInObject(\ )
  1997. may affect valid user descriptors even though it does not take
  1998. and user descriptors as arguments.)
  1999. .(x z
  2000. user descriptor
  2001. .)x \*($n
  2002. .lp
  2003. User descriptors have the following form:
  2004. .(b I
  2005. \fBtypedef struct {
  2006.        char        *basePtr;    /* ptr to start of data */
  2007.        int            byteCount    /* number of bytes accessible */
  2008.        int            objectSize;    /* total size of object */
  2009.        TWO        userFlags;    /* properties field from object header */
  2010.        TWO        type;        /* for use only  by E */
  2011.        TWO        flags;        /* for use only  by E */
  2012.        TWO        tag;        /* tag field from the object header */
  2013.        OID        oid;        /* oid of object being referenced */
  2014. } USERDESC;\fR
  2015. .)b
  2016. .(x z
  2017. USERDESC
  2018. .)x \*($n
  2019. .(x z
  2020. user descriptor
  2021. .)x \*($n
  2022. .lp
  2023. The \*(lqbasePtr\*(rq field of a user descriptor points to the start
  2024. of the object's data in the buffer pool, while the \*(lqbyteCount\*(rq
  2025. field indicates the number of bytes accessible to the application
  2026. program through this user descriptor.
  2027. The value \*(lqobjectSize\*(rq is the length of the entire object.  
  2028. The \*(lquserFlags\*(rq field holds a copy of the  properties field from the
  2029. object's header. 
  2030. The \*(lqtype\*(rq and \*(lqflags\*(rq fields are used by the E language's persistent virtual machine.  
  2031. Finally, the \*(lqtag\*(rq field contains a copy of the \*(lqtag\*(rq field in the object's header.
  2032. .lp
  2033. An object's data is referenced indirectly via the \*(lqbasePtr\*(rq field.
  2034. \fBReferences by the application
  2035. must always be indirect via \*(lqbasePtr\*(rq\fR.
  2036. The indirection is necessary because there are times when the
  2037. Storage Manager moves an object in the buffer pool, and 
  2038. the \*(lqbasePtr\*(rq of each user descriptor that
  2039. references the object is updated to account for the move.  
  2040. .lp
  2041. The remainder of this section describes the Storage Manager
  2042. functions for operating on objects. 
  2043. It is divided into sub-sections that describe 
  2044. creating and destroying objects, 
  2045. pinning and unpinning parts of objects, 
  2046. modifying objects,
  2047. and
  2048. using object headers.
  2049. .br
  2050. .sh 3 "Creating and Destroying Objects"
  2051. .sp
  2052. .(b L
  2053. \fBsm_CreateObject (groupIndex, fid, nearHint, nearObj, objHdr, length, data, oid)
  2054. int         groupIndex;        /* IN buffer group to use */
  2055. FID        *fid;            /* IN file in which object is to be placed */
  2056. int         nearHint;        /* IN flag indicating where to create the new object */
  2057. OID        *nearObj;        /* IN create the new object near this object */
  2058. OBJHDR      *objHdr;        /* IN the object's header */
  2059. int         length;        /* IN amount of data */
  2060. void        *data;            /* IN the initial data for the object */
  2061. OID        *oid;            /* OUT the new object's OID */\fR
  2062. .)b
  2063. .(x z
  2064. sm_CreateObject(\ )
  2065. .)x \*($n
  2066. .lp
  2067. Sm_CreateObject(\ ) creates an object in the file identified by \*(lqfid\*(rq.
  2068. If \*(lqobjHdr\*(rq is not NULL, the \*(lqtag\*(rq field in the header of the new object
  2069. is initialized with the contents of the \*(lqtag\*(rq field in the header
  2070. structure addressed by \*(lqobjHdr\*(rq.
  2071. When \*(lqdata\*(rq is not NULL, the object is initialized with
  2072. the data addressed by the argument \*(lqdata\*(rq;
  2073. in this case, \*(lqlength\*(rq specifies how much data to copy.
  2074. When \*(lqdata\*(rq is NULL, an object of size \*(lqlength\*(rq is created and 
  2075. filled with zeroes.
  2076. .sp
  2077. The argument \*(lqnearHint\*(rq specifies where the new object should be created.  
  2078. The following values, defined in \fCsm_client.h\fR, are near hints:
  2079. NEAR_OBJ, NEAR_FIRST, and NEAR_LAST.  
  2080. If \*(lqnearHint\*(rq is set to NEAR_OBJ,
  2081. the new object is created near the object designated by \*(lqnearObj\*(rq. 
  2082. If \*(lqnearHint\*(rq is set to NEAR_FIRST or NEAR_LAST, \*(lqnearObj\*(rq is
  2083. ignored and the new object is created 
  2084. near the first or last object in the file, respectively.  
  2085. .lp
  2086. If sm_CreateObject(\ ) is successful, the OID structure pointed to
  2087. by \*(lqoid\*(rq is filled with the OID of the new object.
  2088. Sm_CreateObject(\ ) does not leave the new object pinned.
  2089. .(b L
  2090. \fBsm_DestroyObject (groupIndex, oid)
  2091. int         groupIndex;        /* IN buffer group in use */
  2092. OID        *oid;            /* IN the object to destroy */\fR
  2093. .)b
  2094. .(x z
  2095. sm_DestroyObject(\ )
  2096. .)x \*($n
  2097. .lp
  2098. Sm_DestroyObject(\ ) destroys an object.
  2099. If any user descriptors are valid for the object when the object
  2100. is destroyed, they are made invalid, and 
  2101. they must be released with
  2102. sm_ReleaseObject(\ ), described below.
  2103. .br
  2104. .sh 3 "Pinning and Unpinning Objects"
  2105. .sp
  2106. .lp
  2107. The following two functions 
  2108. change the number of pages fixed in the client buffer pool.
  2109. All the other functions that operate on objects fix
  2110. pages temporarily and unfix the pages before returning.
  2111.  
  2112. .(b L
  2113. \fBsm_ReadObject (groupIndex, oid, start, length, userDesc)
  2114. int         groupIndex;        /* IN buffer group in use */
  2115. OID         *oid;            /* IN object to read */
  2116. int        start;            /* IN starting offset of read */
  2117. int        length;        /* IN amount of data to read */
  2118. USERDESC     **userDesc;        /* OUT descriptor to access the data */\fR
  2119. .)b
  2120. .(x z
  2121. sm_ReadObject(\ )
  2122. .)x \*($n
  2123. .lp
  2124. Sm_ReadObject(\ ) reads part or all of the object identified by \*(lqoid\*(rq
  2125. into the buffer group identified by \*(lqgroupIndex\*(rq.
  2126. If \*(lqlength\*(rq is READ_ALL, the entire object is read (assuming that
  2127. the size of the entire object is not greater than the amount of
  2128. unpinned space in the buffer group).
  2129. Otherwise, the bytes to be read are specified by \*(lqstart\*(rq and \*(lqlength\*(rq.
  2130. .lp
  2131. Sm_ReadObject(\ ) pins the specified range of bytes in the buffer pool
  2132. and returns a user descriptor to the caller.
  2133. .(x z
  2134. pin, object
  2135. .)x \*($n
  2136. \fBBytes pinned in the buffer pool by sm_ReadObject(\ ) remain
  2137. pinned until they are explicitly released by sm_ReleaseObject(\ ).\fR
  2138. .lp
  2139. While sm_ReadObject(\ ) can be used to get information about 
  2140. the object (from the object header) by giving it a length of zero,
  2141. sm_ReadObjectHeader(\ ) is the preferred way to meet
  2142. the same objective. 
  2143. Sm_ReadObject(\ ) performs work
  2144. that is unnecessary when only the object header is of interest,
  2145. and it always fixes at least one page in the buffer pool,
  2146. even if the given length is zero.
  2147. .lp
  2148. The user descriptor consumes resources that must be
  2149. freed with sm_ReleaseObject(\ ), even if the object is not pinned 
  2150. .(x z
  2151. sm_ReleaseObject(\ )
  2152. .)x \*($n
  2153. (zero is given for \*(lqlength\*(rq).
  2154. .sp
  2155. .(b L
  2156. \fBsm_ReleaseObject (userDesc)
  2157. USERDESC     *userDesc;        /* IN descriptor returned by ReadObject */\fR
  2158. .)b
  2159. .(x z
  2160. sm_ReleaseObject(\ )
  2161. .)x \*($n
  2162. .lp
  2163. Sm_ReleaseObject(\ )
  2164. unpins a range of bytes of an object that was pinned by sm_ReadObject(\ ),
  2165. and frees the resources associated with the user descriptor.
  2166. If the user descriptor is not valid, 
  2167. sm_ReleaseObject(\ ) sets
  2168. sm_errno to esmBADUSERDESC and returns esmFAILURE.
  2169. .br
  2170. .sh 3 "Modifying Objects"
  2171. .lp
  2172. Four functions modify objects:
  2173. .(x z
  2174. object, modifying
  2175. .)x \*($n
  2176. sm_WriteObject(\ ), 
  2177. sm_InsertInObject(\ ),
  2178. sm_AppendToObject(\ ),
  2179. and sm_DeleteFromObject(\ ).
  2180. Sm_WriteObject(\ ) cannot be used to change the size of an object,
  2181. .(x z
  2182. sm_WriteObject(\ )
  2183. .)x \*($n
  2184. only to overwrite parts of an object.
  2185. The other three functions can change the size of an object.
  2186. These functions provide substantial flexibility, and their efficiency varies.
  2187. Changing the size of a small object (one that fits on a disk page)
  2188. is relatively inexpensive. 
  2189. It is less expensive than reading and writing the object.  
  2190. For large objects, performing many small-size changes can be
  2191. expensive in CPU time and buffer space utilization.
  2192. If a large object is pinned several times simultaneously, through
  2193. different user descriptors,
  2194. updates to the object are very expensive.
  2195. If a large number of small-size changes is required, 
  2196. we recommend accumulating the changes and performing them in larger chunks.
  2197. .sp
  2198. .(b L
  2199. \fBsm_WriteObject (groupIndex, start, length, data, userDesc, release)
  2200. int         groupIndex;        /* IN buffer group in use */
  2201. int        start;            /* IN starting offset of write */
  2202. int        length;        /* IN amount of data to be written */
  2203. void        *data;            /* IN pointer to the data */
  2204. USERDESC     *userDesc;        /* IN descriptor returned by ReadObject */
  2205. BOOL         release;        /* IN whether to release the object */\fR
  2206. .)b
  2207. .(x z
  2208. sm_WriteObject(\ )
  2209. .)x \*($n
  2210. .lp
  2211. Sm_WriteObject(\ ) overwrites the region of bytes from
  2212. (userDesc->baseptr\  +\ start)
  2213. to
  2214. (userDesc->baseptr\ +\  start\ +\ length\ -\ 1)
  2215. with the data addressed by the \*(lqdata\*(rq argument.
  2216. The given byte range must have been pinned (which means that
  2217. the user descriptor must be valid).
  2218. If \*(lqrelease\*(rq is TRUE, the range of bytes given by \*(lquserDesc\*(rq
  2219. is unpinned when sm_WriteObject(\ ) returns.
  2220. If \*(lqdata\*(rq is NULL, the region is filled with zeroes.
  2221. \fBAll updates to objects must be performed using sm_WriteObject(\ )\fR
  2222. so that the updates can be logged, and the 
  2223. transaction semantics can be guaranteed.
  2224. .sp
  2225. .(b L
  2226. \fBsm_InsertInObject (groupIndex, oid, start, length, data)
  2227. int         groupIndex;        /* IN buffer group in use */
  2228. OID        *oid;            /* IN object we're inserting into */
  2229. int        start;            /* IN starting offset of insert */
  2230. int         length;        /* IN amount of data being inserted */
  2231. void        *data;            /* IN data to insert */\fR
  2232. .)b
  2233. .(x z
  2234. sm_InsertInObject(\ )
  2235. .)x \*($n
  2236. .lp
  2237. Sm_InsertInObject(\ ) inserts \*(lqlength\*(rq bytes of data into
  2238. an object, beginning at the offset \*(lqstart\*(rq.
  2239. If \*(lqdata\*(rq is NULL, the inserted region is filled with zeroes.
  2240. If there are any valid user descriptors
  2241. (those for which sm_ReleaseObject(\ ) has not been called)
  2242. for the object at the
  2243. time the insertion takes place, they are reestablished if necessary.
  2244. After the insertion, the base pointers of the valid user descriptors
  2245. point to the byte within the object indicated by
  2246. the \*(lqstart\*(rq argument to the sm_ReadObject(\ ) 
  2247. operation that created the user descriptor. 
  2248. For example, 
  2249. an object's first five bytes, "ABCDE" are pinned 
  2250. by sm_ReadObject(\ ),
  2251. which was called with a \*(lqstart\*(rq offset of zero and a \*(lqlength\*(rq of five.
  2252. Sm_ReadObject(\ ) returns a user descriptor, U, which addresses
  2253. "ABCDE".
  2254. Sm_InsertInObject(\ ) inserts "ZZ" at \*(lqstart\*(rq offset zero.
  2255. The user descriptor U now addresses "ZZABC", which are pinned, while
  2256. the bytes "DE" are no longer pinned.
  2257. .sp
  2258. .(b L
  2259. \fBsm_AppendToObject (groupIndex, oid, length, data)
  2260. int         groupIndex;        /* IN buffer group in use */
  2261. OID        *oid;            /* IN object we are appending data to */
  2262. int        length;        /* IN amount of data being appended */
  2263. void        *data;            /* IN data to append */\fR
  2264. .)b
  2265. .(x z
  2266. sm_AppendToObject(\ )
  2267. .)x \*($n
  2268. .lp
  2269. Sm_AppendToObject(\ ) appends \*(lqlength\*(rq bytes of data to the end of an object.
  2270. Outstanding user descriptors are handled the same way as
  2271. sm_InsertInObject(\ ).
  2272. If \*(lqdata\*(rq is NULL, the appended region is filled with zeroes.
  2273. .sp
  2274. .(b L
  2275. \fBsm_DeleteFromObject (groupIndex, oid, start, length)
  2276. int         groupIndex;        /* IN buffer group in use */
  2277. OID        *oid;            /* IN object we're inserting into */
  2278. int        start;            /* IN starting offset of delete */
  2279. int        length;        /* IN amount of data being deleted */\fR
  2280. .)b
  2281. .(x z
  2282. sm_DeleteFromObject(\ )
  2283. .)x \*($n
  2284. .lp
  2285. Sm_DeleteFromObject(\ ) deletes \*(lqlength\*(rq bytes of 
  2286. data from an object, beginning with the byte indicated by
  2287. the offset \*(lqstart\*(rq.
  2288. .(x z
  2289. user descriptor 
  2290. .)x \*($n
  2291. Sm_DeleteFromObject(\ ) is analogous to sm_InsertObject(\ ).
  2292. All valid user descriptors affected by the deletion are, 
  2293. if possible, reset to point to the new absolute
  2294. offset within the object.
  2295. There are two cases when this is not possible.
  2296. .np 
  2297. The object's size is now smaller
  2298. than the starting offset of a user descriptor.
  2299. The \*(lqbasePtr\*(rq field
  2300. in the user descriptor is set to NULL and 
  2301. the user descriptor is made invalid.
  2302. The user descriptor must be released by sm_ReleaseObject(\ )
  2303. so that its resources can be reclaimed.
  2304. .np
  2305. The object's size is now smaller than the original
  2306. byte range addressable by a user descriptor.
  2307. The size of the range addressable by the descriptor is
  2308. reduced to reflect the new size of the object.
  2309. .br
  2310. .sh 3 "Object Headers"
  2311. .(x z
  2312. object header
  2313. .)x \*($n
  2314. .sp
  2315. .(b L
  2316. \fBsm_ReadObjectHeader (groupIndex, oid, objHdr)
  2317. int         groupIndex;        /* IN buffer group in use */
  2318. OID        *oid;            /* IN read this object's header */
  2319. OBJHDR      *objHdr;        /* OUT place to put the header */\fR
  2320. .)b
  2321. .(x z
  2322. sm_ReadObjectHeader
  2323. .)x \*($n
  2324. .lp
  2325. Sm_ReadObjectHeader(\ ) reads an object's header 
  2326. into the structure addressed by \*(lqobjHdr\*(rq.
  2327. This function is the preferred one to use to determine
  2328. if an object's identifier is valid.
  2329. If the object's identifier is invalid, Sm_ReadObjectHeader(\ )
  2330. returns esmFAILURE and puts esmBADOID in sm_errno.
  2331. .sp
  2332. .(b L
  2333. \fBsm_SetObjectHeader (groupIndex, oid, objHdr)
  2334. int         groupIndex;        /* IN buffer group in use */
  2335. OID        *oid;            /* IN set this object's header flags */
  2336. OBJHDR      *objHdr;        /* IN the new header */\fR
  2337. .)b
  2338. .(x z
  2339. sm_SetObjectHeader
  2340. .)x \*($n
  2341. .lp
  2342. Sm_SetObjectHeader(\ ) modifies an object's header.
  2343. Only the \*(lqtags\*(rq field is modified; the other
  2344. fields are read-only.
  2345. .br
  2346. .sh 2 "Versions of Objects"
  2347. .(x z
  2348. version of object
  2349. .)x \*($n
  2350. .lp
  2351. In order to allow efficient updating of shared data, 
  2352. the Storage Manager offers versions of objects.
  2353. Versions come in two kinds:
  2354. \fIworking versions\fR and \fIfrozen versions\fR.  
  2355. .(x z
  2356. version, working
  2357. .)x \*($n
  2358. .(x z
  2359. working version
  2360. .)x \*($n
  2361. .(x z
  2362. version, frozen
  2363. .)x \*($n
  2364. .(x z
  2365. frozen version
  2366. .)x \*($n
  2367. A working version of an object is one that can be modified.
  2368. Every object has at least one version, which is the object itself.
  2369. A working version may be frozen, after which it can no longer be modified.  
  2370. .lp
  2371. A new working version, called a \fIdescendent\fR,
  2372. can be made of a frozen object.
  2373. The descendent looks like a new object that is a copy of the
  2374. frozen object from which it came.
  2375. The Storage Manager determines when it is necessary and efficient
  2376. to make a copy of the frozen object, and makes the copy at that time.
  2377. .sp
  2378. .(b L
  2379. \fBsm_CreateVersion (groupIndex, nearHint, parentObj, nearObj, oid)
  2380. int         groupIndex;        /* IN buffer group to use */
  2381. int         nearHint;        /* IN flag indicating where to create the new version near */
  2382. OID        *parentObj;        /* IN object to create a version of */
  2383. OID        *nearObj;        /* IN create the new version near this object */
  2384. OID        *oid;            /* OUT the new version's OID */\fR
  2385. .)b
  2386. .(x z
  2387. sm_CreateVersion
  2388. .)x \*($n
  2389. .lp
  2390. Sm_CreateVersion(\ ) creates a new version of the object \*(lqparentObj\*(rq in
  2391. the file containing \*(lqparentObj\*(rq.  
  2392. The arguments \*(lqgroupIndex\*(rq, \*(lqnearHint\*(rq, and \*(lqnearObj\*(rq are 
  2393. used as in sm_CreateObject(\ ).  
  2394. The object identifier of the new version is returned in \*(lqoid\*(rq.  
  2395. \fBThe object identified by \*(lqparentObj\*(rq must be a frozen version\fR.  
  2396. The new version is a working version.  
  2397. The new version can be destroyed using sm_DestroyObject(\ ).  
  2398. When a new version is created, the P_VERSIONED property is set in 
  2399. the object header.
  2400. .lp
  2401. Like sm_CreateObject(\ ), sm_CreateVersion(\ ) does not leave anything
  2402. pinned in the buffer pool.
  2403. .sp
  2404. .(b L
  2405. \fBsm_FreezeVersion (groupIndex, oid)
  2406. int         groupIndex;        /* IN buffer group to use */
  2407. OID        *oid;            /* IN object to be frozen */\fR
  2408. .)b
  2409. .(x z
  2410. sm_FreezeVersion
  2411. .)x \*($n
  2412. .lp
  2413. Sm_FreezeVersion(\ ) marks an object as frozen, preventing 
  2414. subsequent modification of the object, and allowing new working
  2415. versions to be made from this object.
  2416. When an object is frozen, both
  2417. the P_VERSIONED and the P_FROZEN properties are set in the object
  2418. header.
  2419. Once frozen, an object cannot be unfrozen.
  2420. A frozen object can be destroyed.
  2421. .br
  2422. .sh 2 "Operations on Files"
  2423. .(x z
  2424. file, what is a
  2425. .)x \*($n
  2426. .(x z
  2427. file, operations on 
  2428. .)x \*($n
  2429. .lp
  2430. A Storage Manager file is a flexible container in which objects are 
  2431. place when they are created.
  2432. No object exists outside a file.
  2433. .lp
  2434. The objects in a file can be \fIscanned\fR, meaning that
  2435. .(x z
  2436. scanning a file
  2437. .)x \*($n
  2438. they are visited exactly once.
  2439. .lp
  2440. Files do not have preallocated space or ownership properties.
  2441. Various consistency guarantees can be associated with files,
  2442. with the effect that updating data in different files has 
  2443. different costs.
  2444. .lp
  2445. The Storage Manager offers operations 
  2446. for creating, destroying, scanning, bulk-loading files,
  2447. and for changing the consistency guarantees associated with files.
  2448. Some operations on files acquire locks on entire files.
  2449. The locks acquired are described in Appendix A.
  2450. .lp
  2451. A file is identified by a unique file identifier or FID.  
  2452. The Storage Manager does not provide a way to find all files or
  2453. file identifiers that exist, so  
  2454. it is left to the application to keep track of its file identifiers.
  2455. .(x z
  2456. FID
  2457. .)x \*($n
  2458. .(x z
  2459. file identifier
  2460. .)x \*($n
  2461. For example, consider an  application that 
  2462. embeds file identifiers in objects to create a logical hierarchy of files.
  2463. The application had best destroy the files 
  2464. in a depth-first fashion, lest it lose a file identifier 
  2465. before the file it identifies is destroyed.
  2466. .lp
  2467. The following two macros can be used to give a file identifier
  2468. an illegitimate initial value, and later to recognize that value:
  2469. .(b I
  2470. \fBINVALIDATE_FID (FID fid)\fR 
  2471. .)b
  2472. .(x z
  2473. INVALIDATE_FID
  2474. .)x \*($n
  2475. sets \*(lqfid\*(rq to an invalid file identifier.
  2476. .(b I
  2477. \fBFID_IS_INVALID (FID fid)\fR 
  2478. .)b
  2479. .(x z
  2480. FID_IS_INVALID
  2481. .)x \*($n
  2482. returns TRUE if \*(lqfid\*(rq is the invalid identifier given by
  2483. INVALIDATE_FID(\ ), FALSE otherwise.
  2484. .lp
  2485. The rest of this section describes operations on files
  2486. and operations that concern entire files of objects.
  2487. .sh 3 "Consistency Guarantees for Files"
  2488. .(x z
  2489. files, consistency guarantees for
  2490. .)x \*($n
  2491. .lp
  2492. The \fIlog level\fR of a file determines what 
  2493. .(x z
  2494. files, log level
  2495. .)x \*($n
  2496. level of consistency is maintained for the file
  2497. in the event that a transaction aborts or a server crashes.
  2498. There are two log levels for files on data volumes:  
  2499. LOG_ALL and LOG_SPACE.
  2500. LOG_ALL indicates that consistency is maintained for user data and
  2501. meta-data.
  2502. LOG_SPACE indicates that meta-data are guaranteed to be consistent.
  2503. This means that all objects are available and that they are
  2504. the correct size, but their contents may be corrupted.
  2505. Files that have their log level set to LOG_SPACE are
  2506. flushed when the transaction is committed.  
  2507. \fBData pages for 
  2508. large objects (objects that do not fit on a single disk page) may not be 
  2509. flushed, so there is no guarantee
  2510. that the data is safely on disk until 
  2511. the server dismounts the volume.\fR
  2512. The log level is not a permanent attribute of a file.  
  2513. When an application sets the log level for a file, 
  2514. the setting lasts until it is changed or until sm_ShutDown(\ ) is called.
  2515. If, in a transaction, the log level for a file is changed from 
  2516. LOG_SPACE to LOG_ALL, the Storage Manager guarantees only 
  2517. that the meta-data are consistent.
  2518. .lp
  2519. LOG_ALL is the default log level for data files.
  2520. .(x z
  2521. log level, default
  2522. .)x \*($n
  2523. .(x z
  2524. default log level
  2525. .)x \*($n
  2526. LOG_SPACE is designed to conserve
  2527. log space and increase performance for those files whose data 
  2528. integrity is not critical.  
  2529. For example, results of a query may be stored in a
  2530. file with its log level set to LOG_SPACE,
  2531. since file can be regenerated, in the event of a failure.
  2532. To conserve log space when loading a large file,
  2533. the log level for a file may be set to LOG_SPACE.  
  2534. Once the loading transaction is committed, 
  2535. the log level should be set to LOG_ALL.
  2536. .lp
  2537. Files on temporary volumes can have only one log level: LOG_NONE.
  2538. .(x z
  2539. temporary volume
  2540. .)x \*($n
  2541. See 
  2542. Section 5.1.3, \fBTemporary Volumes\fR,
  2543. for more information about temporary volumes.
  2544. .lp
  2545. Sm_SetLogLevel(\ ) is used to change the log level for a list
  2546. of files:
  2547. .sp
  2548. .(b L
  2549. \fBsm_SetLogLevel (logLevel, fileCount, fids)
  2550. int        logLevel;            /* IN log level */
  2551. int        fileCount;            /* IN number of files to set level for */
  2552. FID        fid[];                /* IN list of files to set level for */ \fR
  2553. .)b
  2554. .(x z
  2555. sm_SetLogLevel(\ )
  2556. .)x \*($n
  2557. .lp
  2558. The \*(lqlogLevel\*(rq argument takes
  2559. the values LOG_SPACE and LOG_ALL.
  2560. The \*(lqfileCount\*(rq argument indicates the size of the
  2561. last argument, \*(lqfid[]\*(rq,
  2562. which is a list of file identifiers of the files whose log
  2563. levels are to be affected by this function.
  2564. It is not an error for a file in the list already
  2565. to have the given log level.
  2566. .lp
  2567. If \*(lqfileCount\*(rq is zero, 
  2568. \fBall\fR files are given \*(lqlogLevel\*(rq.
  2569. .lp
  2570. The volumes on which the files
  2571. reside must be available for mounting, 
  2572. and a side effect of setting the log level 
  2573. is that the volumes are mounted.
  2574. .lp
  2575. Sm_SetLogLevel(\ ) has no effect on files that
  2576. reside on temporary volumes 
  2577. .(x z
  2578. temporary volume
  2579. .)x \*($n
  2580. (see Section 5.1.3, \fBTemporary Volumes\fR).
  2581. .(b L
  2582. \fBsm_CreateFile (groupIndex, volid, fid)
  2583. int         groupIndex;            /* IN buffer group in use */
  2584. VOLID     volid;                /* IN the volume in which to place the file */
  2585. FID        *fid;                /* OUT the file ID of the new file */
  2586. .)b
  2587. .(x z
  2588. sm_CreateFile(\ )
  2589. .)x \*($n
  2590. .lp
  2591. Sm_CreateFile(\ ) creates a new file on the volume indicated by \*(lqvolid\*(rq.
  2592. The file identifier of the new file is returned in the structure
  2593. to which \*(lqfid\*(rq points.
  2594. The caller is responsible for allocating space for the FID.
  2595. .sp
  2596. .(b L
  2597. \fBsm_DestroyFile (groupIndex, fid)
  2598. int         groupIndex;            /* IN buffer group in use */
  2599. FID        *fid;                /* IN the file to destroy */\fR
  2600. .)b
  2601. .(x z
  2602. sm_DestroyFile(\ )
  2603. .)x \*($n
  2604. .lp
  2605. Sm_DestroyFile(\ ) destroys the file identified by \*(lqfid\*(rq.
  2606. The objects in the file are destroyed along with the file.
  2607. Disk space is released when the transaction is committed.
  2608. .sp
  2609. .(b L
  2610. \fBsm_GetFirstOid (groupIndex, fid, oid, objHdr, emptyFlag)
  2611. int         groupIndex;            /* IN buffer group in use */
  2612. FID        *fid;                /* IN the file */
  2613. OID        *oid;                /* OUT first OID */
  2614. OBJHDR      *objHdr;            /* OUT the object's header */
  2615. BOOL        *emptyFlag;            /* OUT empty file flag */\fR
  2616. .)b
  2617. .(x z
  2618. sm_GetFirstOid(\ )
  2619. .)x \*($n
  2620. .lp
  2621. Sm_GetFirstOid(\ ) retrieves the object identifier and the
  2622. object header of the first object in the file designated by \*(lqfid\*(rq.  
  2623. The first object is the first object on the first physical page in the file.
  2624. If the file does not contain any objects, \*(lqemptyFlag\*(rq is set to TRUE.
  2625. .sp
  2626. .(b L
  2627. \fBsm_GetLastOid (groupIndex, fid, oid, objHdr, emptyFlag)
  2628. int         groupIndex;            /* IN buffer group in use */
  2629. FID        *fid;                /* IN the file */
  2630. OID        *oid;                /* OUT last OID */
  2631. OBJHDR      *objHdr;            /* OUT the object's header */
  2632. BOOL        *emptyFlag;            /* OUT empty file flag */\fR
  2633. .)b
  2634. .(x z
  2635. sm_GetLastOid(\ )
  2636. .)x \*($n
  2637. .lp
  2638. Sm_GetLastOid(\ ) retrieves the object identifier and 
  2639. the object header of the last object in
  2640. the file designated by \*(lqfid\*(rq. 
  2641. The last object is the 
  2642. last object on the last physical page in the file.
  2643. If the file does not contain any objects, \*(lqemptyFlag\*(rq is set to TRUE.
  2644. .sp
  2645. .(b L
  2646. \fBsm_GetNextOid (groupIndex, baseOid, nextOid, objHdr, endMarker)
  2647. int         groupIndex;            /* IN buffer group in use */
  2648. OID        *baseOid;            /* IN next relative to this object */
  2649. OID        *nextOid;            /* OUT OID of the next object */
  2650. OBJHDR      *objHdr;            /* OUT the object's header */
  2651. BOOL            *endMarker;            /* OUT end-of-file flag */\fR
  2652. .)b
  2653. .(x z
  2654. sm_GetNextOid(\ )
  2655. .)x \*($n
  2656. .lp
  2657. Sm_GetNextOid(\ ) retrieves the object identifier and 
  2658. the object header of the next object
  2659. in the file relative to the object addressed by \*(lqbaseOid\*(rq. 
  2660. \*(lqEndMarker\*(rq is set to TRUE when end-of-file is reached
  2661. (i.e., when there is no next object for sm_GetNextOid(\ ) to return).
  2662. .lp
  2663. The next object is that which resides \fIphysically\fR next in the file.
  2664. There is no way to scan a file's objects in the order in 
  2665. which they were inserted in the file.
  2666. .lp
  2667. The preferred method for retrieving all the objects in a file is to 
  2668. use scans, described in the next sub-section.
  2669. Scans are more efficient than using sm_GetNextOid(\ ), which is
  2670. present for backward compatibility.
  2671. .sp
  2672. .(b L
  2673. \fBsm_GetPreviousOid (groupIndex, baseOid, prevOid, objHdr, endMarker)
  2674. int         groupIndex;            /* IN buffer group in use */
  2675. OID        *baseOid;            /* IN previous relative to this object */
  2676. OID        *prevOid;            /* OID of the previous object */
  2677. OBJHDR      *objHdr;            /* OUT the object's header */
  2678. BOOL            *endMarker;            /* OUT start-of-file flag */
  2679. .)b
  2680. .(x z
  2681. sm_GetPreviousOid(\ )
  2682. .)x \*($n
  2683. .lp
  2684. Sm_GetPreviousOid(\ ) retrieves the object identifier and object
  2685. header of the previous object in the file relative to the object addressed
  2686. by \*(lqbaseOid\*(rq. 
  2687. \*(lqEndMarker\*(rq is set to TRUE when start-of-file is reached
  2688. (i.e., when there is no next object for sm_GetPreviousOid(\ ) to return).
  2689. Much like sm_GetNextOid(\ ), the previous object 
  2690. is the object that is \fIphysically\fR previous in the file.
  2691. .br
  2692. .sh 3 "Scanning Files"
  2693. .lp
  2694. The objects in a file can be visited most efficiently by scanning the
  2695. file.  
  2696. During a \fIscan\fR, the client library 
  2697. locks the entire file so that 
  2698. while one application is using the file, 
  2699. objects cannot be inserted, deleted, or changed by another application. 
  2700. \fBThe Storage Manager does not support a single application's
  2701. modifying a file during a scan.\fR
  2702.  
  2703. The client library also some information
  2704. about the state of the scan and the structure of the file being
  2705. scanned.
  2706. The information is stored in a 
  2707. \fIscan descriptor\fR, a structure of type \fBSCANDESC\fR,
  2708. which is meant to be treated as \fIopaque\fR by the application.
  2709. .sp
  2710. .(b L
  2711. \fBsm_OpenScanWithGroup (fid, type, groupIndex, scanDesc, oid)
  2712. FID        *fid;                /* IN file to scan */
  2713. int        type;                /* IN type of scan -- UNUSED */
  2714. int        groupIndex;            /* IN buffer group for use in scan */
  2715. SCANDESC    **scanDesc;            /* OUT returned scan descriptor */
  2716. OID        *oid;                /* IN optional oid to begin scan -- UNUSED */
  2717. .)b
  2718. .(x z
  2719. sm_OpenScanWithGroup(\ )
  2720. .)x \*($n
  2721. .lp
  2722. Sm_OpenScanWithGroup(\ ) initializes a 
  2723. scan on the file indicated by \*(lqfid\*(rq.
  2724. A scan descriptor is passed back in \*(lqscanDesc\*(rq, for use
  2725. in subsequent scan calls.  
  2726. Using the scan mechanism can be considerably more efficient 
  2727. that using the sm_GetNextOid(\ ) call or sm_ReadObject(\ ).
  2728. Scans use a buffer group, \*(lqgroupIndex\*(rq.  
  2729. This group should be created 
  2730. with the most-recently-used replacement policy,
  2731. and its size should be tuned to 
  2732. reflect the buffering requirements for the scan.  
  2733. The buffer group should have a size of at least five pages.
  2734. .lp
  2735. Objects are scanned in the order in which they physically reside on disk.
  2736. After sm_OpenScanWithGroup(\ ) returns, the scan pointer is
  2737. before the first object in the file.  This is true even if
  2738. the file is empty, in which case the first call to sm_ScanNextObject(\ )
  2739. returns a flag indicating the end-of-file condition.
  2740. The \*(lqtype\*(rq and \*(lqoid\*(rq arguments are not used and are
  2741. present for backward compatibility.
  2742. .sp
  2743. .(b L
  2744. \fBsm_OpenScan (fid, type, groupSize, scanDesc, oid)
  2745. FID        *fid;                /* IN file to scan */
  2746. int        type;                /* IN type of scan -- UNUSED */
  2747. int        groupSize;            /* IN size of buffer group in pages */
  2748. SCANDESC    **scanDesc;            /* OUT returned scan descriptor */
  2749. OID        *oid;                /* IN optional oid to begin scan -- UNUSED */
  2750. .)b
  2751. .(x z
  2752. sm_OpenScan(\ )
  2753. .)x \*($n
  2754. .lp
  2755. Sm_OpenScan(\ ) is like 
  2756. sm_OpenScanWithGroup(\ ), but it is 
  2757. less flexible, and it is provided for backward compatibility.  
  2758. It is identical to sm_OpenScanWithGroup(\ ) 
  2759. except that it creates a buffer group with
  2760. the most-recently-used replacement policy and size 
  2761. \*(lqgroupSize\*(rq.  
  2762. \*(lqGroupSize\*(rq should be at least five (pages).
  2763. The buffer group is destroyed when the scan is closed.
  2764. .sp  
  2765. .(b L
  2766. \fBsm_ScanNextObject (scanDesc, start, length, retDesc, eof)
  2767. SCANDESC    *scanDesc;            /* IN scan descriptor */
  2768. int        start;                /* IN starting offset in object */
  2769. int        length;            /* IN number of bytes to read */
  2770. USERDESC     **retDesc;            /* OUT descriptor to access the data */
  2771. BOOL        *eof;                /* OUT end of file indicator */
  2772. .)b
  2773. .(x z
  2774. sm_ScanNextObject(\ )
  2775. .)x \*($n
  2776. .lp
  2777. sm_ScanNextObject(\ ) reads the next object in the file 
  2778. and pins the object as if sm_ReadObject(\ ) were used.
  2779. \*(lqScanDesc\*(rq is the scan descriptor returned when the scan was opened.
  2780. \*(lqStart\*(rq is the starting offset within the object to return.  
  2781. .lp
  2782. \*(lqLength\*(rq is the length of the object read to
  2783. perform.  
  2784. If \*(lqlength\*(rq is READ_ALL, the entire object is read (assuming
  2785. that the size of the entire object is not greater than the amount of
  2786. unpinned space in the buffer group).  
  2787. To obtain the object header and OID information for the object, 
  2788. use a \*(lqlength\*(rq of zero.
  2789. .lp
  2790. sm_ScanNextObject(\ ) returns a user descriptor for the object,
  2791. if there is one to pin, whether or not any bytes are pinned.
  2792. \*(lqEof\*(rq is set to TRUE and  
  2793. \*(lqretDesc\*(rq is set to NULL
  2794. when there are no more objects to be scanned.
  2795. Each call to sm_ScanNextObject(\ ) releases the user descriptor
  2796. returned by the previous scan call, so 
  2797. \fBsm_ReleaseObject(\ ) must not be used\fR
  2798. .(x z
  2799. sm_ReleaseObject(\ )
  2800. .)x \*($n
  2801. on user descriptors that are acquired by scanning files.
  2802. .sp
  2803. .(b L
  2804. \fBsm_ScanNextBytes (scanDesc, length)
  2805. SCANDESC    *scanDesc;            /* IN scan descriptor */
  2806. int        length;            /* IN number of bytes to read */
  2807. .)b
  2808. .(x z
  2809. sm_ScanNextBytes(\ )
  2810. .)x \*($n
  2811. .lp
  2812. Sm_ScanNextBytes(\ ) is useful when a file being scanned contains very
  2813. large objects that cannot be expected to fit in memory.  
  2814. A sm_ScanNextObject(\ ) call can be made with a relatively small length to
  2815. read in the first section of an object.  
  2816. Sm_ScanNextBytes(\ ) is used subsequently to iterate over the rest of 
  2817. that object, with each call reading in the next \*(lqlength\*(rq bytes 
  2818. of the current scan object.  The iteration can
  2819. be controlled by observing the objectSize field of the user
  2820. descriptor.  esmENDOFOBJECT is returned if there are no more bytes
  2821. to be read in the current object.
  2822. .sp
  2823. .(b L
  2824. \fBsm_CloseScan (scanDesc)
  2825. SCANDESC    *scanDesc;            /* IN scan descriptor */
  2826. .)b
  2827. .(x z
  2828. sm_CloseScan(\ )
  2829. .)x \*($n
  2830. .lp
  2831. Sm_CloseScan(\ ) closes the scan 
  2832. associated with \*(lqscanDesc\*(rq.
  2833. It releases the scan descriptor 
  2834. and the user descriptors and data pinned during
  2835. the scan.
  2836. .br
  2837. .sh 3 "Bulk-loading Files"
  2838. .lp
  2839. \fBWARNING\fR: the file bulk load facility does not work properly in
  2840. version \*V.  We recommend that it not be used.
  2841. .sp
  2842. .(b L
  2843. \fBsm_OpenLoad (fid, type, groupSize, fillFactor, loadDesc)
  2844. FID        *fid;                /* IN file to scan */
  2845. int        groupSize;            /* IN size of load buffer group */
  2846. float        fillFactor;            /* IN fill percentage */
  2847. LOADDESC    **loadDesc;            /* OUT returned load descriptor */
  2848. .)b
  2849. .(x z
  2850. sm_OpenLoad(\ )
  2851. .)x \*($n
  2852. .lp
  2853. Sm_OpenLoad(\ ) prepares to load a set of objects into a file in bulk.
  2854. Bulk loading a file can be more efficient than using a series of
  2855. sm_CreateObject(\ ) calls.
  2856. The file, indicated by \*(lqfid\*(rq,  need not be empty, in which case the new objects
  2857. are added to the end of the file.  
  2858. The load mechanism creates and uses its own buffer group;
  2859. the size of the buffer group is \*(lqgroupSize\*(rq.
  2860. .\" The \*(lqfillFactor\*(rq indicates how full to fill pages with objects.
  2861. .\" A valid value is in the range 0.00 to 1.00, inclusive; 0.00 indicates empty and 1.00 indicates full.  
  2862. The \*(lqfillFactor\*(rq argument is ignored; it is present for future extensions.
  2863. A \fIload descriptor\fR, \*(lqloadDesc\*(rq is 
  2864. .(x z
  2865. load descriptor
  2866. .)x \*($n
  2867. returned for use in subsequent operations (
  2868. sm_LoadNextObject(\ ) and
  2869. sm_CloseLoad(\ )).
  2870. .sp
  2871. .(b L
  2872. \fBsm_LoadNextObject (loadDesc, length, data, oid)
  2873. LOADDESC    *loadDesc;            /* IN load descriptor */
  2874. int        length;            /* IN length of the object */
  2875. void        *data;                /* IN the object's data */
  2876. OID        *oid;                /* OUT returned new object id */
  2877. .)b
  2878. .(x z
  2879. sm_LoadNextObject(\ )
  2880. .)x \*($n
  2881. .lp
  2882. Sm_LoadNextObject(\ ) creates a new object if size
  2883. \*(lqlength\*(rq
  2884. in the file for which the \*(lqloadDesc\*(rq was opened.  
  2885. The new object is initialized with \*(lqdata\*(rq. 
  2886. If \*(lqdata\*(rq is NULL, the object is filled with zeroes.
  2887. Sm_LoadNextObject(\ ) returns an object identifier for the new object in 
  2888. \*(lqoid\*(rq.
  2889. .sp
  2890. .(b L
  2891. \fBsm_CloseLoad (loadDesc)
  2892. LOADDESC    *loadDesc;            /* IN load to close */\fR
  2893. .)b
  2894. .(x z
  2895. sm_CloseLoad(\ )
  2896. .)x \*($n
  2897. .lp
  2898. Sm_CloseLoad(\ ) ends the bulk-load operation.
  2899. .br
  2900. .sh 2 "Operations on Indexes"
  2901. .(x z
  2902. index, operations on
  2903. .)x \*($n
  2904. .lp
  2905. The Storage Manager's index facility associates keys with 
  2906. fixed-length elements.  
  2907. The keys can be any basic C data type 
  2908. (SM_int, SM_long, SM_short, SM_float, SM_double) or strings (SM_string). 
  2909. The size of the element is fixed when the index is created.
  2910. .lp
  2911. B\*[+\*]tree 
  2912. index and linear hashing index functions are
  2913. implemented.  
  2914. B\*[+\*]tree 
  2915. provides fast index lookup 
  2916. on all kinds of queries, especially range queries.  
  2917. Linear hashing provides even faster index lookup and supports linear space growth 
  2918. for dynamically growing indexes, but
  2919. it supports only exact-match queries.
  2920. More information about linear hashing can be found in [Litw88].
  2921. .lp
  2922. A key is fully described by the \fBKEY\fR structure:
  2923. .sp
  2924. .(b L
  2925. \fBtypedef struct {
  2926.     TWO     length;    /* length of the key */    
  2927.     void*    valuePtr;    /* pointer to value of the key */
  2928. } KEY; \fR
  2929. .)b
  2930. .(x z
  2931. KEY
  2932. .)x \*($n
  2933. .lp
  2934. Index keys are compared according to the key type given when
  2935. the index is created.
  2936. The key type determines the number of bytes considered in a key 
  2937. comparison.
  2938. In the case of keys that are strings, the length fields in the keys
  2939. in question determine the number of bytes compared.
  2940. Strings are compared one character at a time.
  2941. The client library does not terminate strings with nulls.
  2942. When two strings of different lengths are compared, the shorter
  2943. string is compared with the corresponding substring of the longer string.
  2944. If the shorter string and the corresponding substring are equal,
  2945. the longer string is considered to be the larger of the two.
  2946. This means that "abc\0" is longer than "abc".
  2947. .lp
  2948. Characters are compared as ASCII values.
  2949. .sh 3 "Creating and Destroying Indexes "
  2950. .lp
  2951. When an index is created, the client library creates a handle,
  2952. by which the index is identified in subsequent operations.
  2953. The handle is an \fIindex identifier\fR, a structure of type IID.
  2954. .(x z
  2955. index identifier
  2956. .)x \*($n
  2957. The value  of the index identifier can be treated as an 
  2958. opaque value by the application.
  2959. .lp
  2960. The following macros can be used it give
  2961. an illegitimate initial value to an
  2962. index identifier, and later to recognize that value:
  2963. .(b I
  2964. \fBINVALIDATE_IID (IID iid)\fR 
  2965. .)b
  2966. sets \*(lqiid\*(rq to an invalid index identifier.
  2967. .(b I
  2968. \fBIID_IS_INVALID (IID iid)\fR 
  2969. .)b
  2970. returns TRUE if \*(lqiid\*(rq has the value given by 
  2971. INVALIDATE_IID(\ ), FALSE if not.
  2972. .lp
  2973. The rest of this section describes the functions that
  2974. .(x z
  2975. index, operations on
  2976. .)x \*($n
  2977. .(x z
  2978. index
  2979. .)x \*($n
  2980. operate on indexes.
  2981. .sp
  2982. .(b L
  2983. \fBsm_CreateIndex(volume, groupIndex, ndxType, keyType, maxKeyLen, elSize, unique, ndx)
  2984. VOLID        volume;        /* IN volume on which index is to be built */
  2985. int            groupIndex;        /* IN the buffer group to use */
  2986. SMTYPE        ndxType;        /* IN SM_BTREENDX, SM_HASHNDX, etc */
  2987. SMDATATYPE    keyType;        /* IN SM_int, SM_long, SM_string, etc */
  2988. int            maxKeyLen;        /* IN maximum key length of a key in the index */
  2989. int            elSize;            /* IN element size (mpl of 4, < SM_MAXELEMLEN) */
  2990. BOOL            unique;        /* IN TRUE if key is unique */
  2991. IID*            ndx;             /* OUT returned index identifier */ \fR    
  2992. .)b
  2993. .(x z
  2994. sm_CreateIndex(\ )
  2995. .)x \*($n
  2996. .lp
  2997. Sm_CreateIndex(\ ) creates an index that resides on \*(lqvolume\*(rq. \**
  2998. .(f
  2999. \** Indexes on temporary volumes are not implemented.
  3000. (Section 5.1.3, \fBTemporary Volumes\fR).
  3001. If the volume given is temporary, sm_CreateIndex(\ )
  3002. returns esmFAILURE, with error code esmNOTIMPLEMENTED.
  3003. .)f
  3004. \*(lqNdxType\*(rq specifies the type of index 
  3005. (SM_BTREENDX for 
  3006. B\*[+\*]tree 
  3007. or SM_HASHNDX for linear hashing).
  3008. \*(lqKeyType\*(rq indicates the data type of the key.
  3009. The maximum length of a key in the index is given in \*(lqmaxKeyLen\*(rq. 
  3010. The size of the elements in the index is given in \*(lqelSize\*(rq. 
  3011. The element size  must be a multiple of four and less than 
  3012. SM_MAXELEMLEN (20). 
  3013. If \*(lqunique\*(rq is FALSE, 
  3014. the index is able to store multiple elements under the same key.
  3015. An index identifier is returned in \*(lqndx\*(rq upon successful completion.
  3016. .sp
  3017. .(b L
  3018. \fBsm_DestroyIndex(ndx, groupIndex)
  3019. IID*            ndx;             /* IN id of index to destroy */
  3020. int             groupIndex;        /* IN which buffer group to use */\fR
  3021. .)b
  3022. .(x z
  3023. sm_DestroyIndex(\ )
  3024. .)x \*($n
  3025. .lp
  3026. Sm_DestroyIndex(\ ) destroys the index associated with \*(lqndx\*(rq.
  3027. .sp
  3028. .(b L
  3029. \fBsm_SetLHashLoadThreshold(ndx, groupIndex, load)
  3030. IID*            ndx;            /* IN index identifier */
  3031. int            groupIndex;        /* IN which buffer group to use */
  3032. float            loadFactor;        /* IN the load factor to use for linear hashing */
  3033. .)b
  3034. .(x z
  3035. sm_SetLHashLoadThreshold(\ )
  3036. .)x \*($n
  3037. .lp
  3038. Sm_SetLHashLoadThreshold(\ ) 
  3039. changes the load factor for a linear hashing index from the 
  3040. default 75% to the given \*(lqloadFactor\*(rq.
  3041. .(x z
  3042. load factor, default for linear hashing indexes
  3043. .)x \*($n
  3044. .(x z
  3045. default load factor
  3046. .)x \*($n
  3047. The default load factor, 75%, yields the best
  3048. access time and space utilization.
  3049. See [Litw88] for information about linear hashing and 
  3050. when it might be useful to change the load factor.
  3051. The load factor can be set only on a newly created index.
  3052. .br
  3053. .sh 3 "Inserting and Removing Index Elements "
  3054. .sp
  3055. .(b L
  3056. \fBsm_InsertEntry(ndx, groupIndex, key, elem)
  3057. IID*            ndx;            /* IN index identifier */
  3058. int            groupIndex;        /* IN which buffer group to use */
  3059. KEY*            key;            /* IN key to insert */
  3060. void*            elem;            /* IN element associated with key */ \fR
  3061. .)b
  3062. .(x z
  3063. sm_InsertEntry(\ )
  3064. .)x \*($n
  3065. .lp
  3066. Sm_InsertEntry(\ ) inserts a <key, elem> pair into the index \*(lqndx\*(rq. 
  3067. If \*(lqndx\*(rq is a unique index and the key to be inserted already appears
  3068. in the index, sm_InsertEntry(\ ) returns an error in sm_errno.
  3069. If the index is not unique, there is no limit to the number
  3070. of duplicate keys as long as different elements are associated with them.
  3071. .sp
  3072. .(b L
  3073. \fBsm_RemoveEntry(ndx, groupIndex, key, elem)
  3074. IID*            ndx;            /* IN index identifier */
  3075. int            groupIndex;        /* IN which buffer group to use */
  3076. KEY*            key;            /* IN key to remove */
  3077. void*            elem;            /* IN element associated with key */ \fR
  3078. .)b
  3079. .(x z
  3080. sm_RemoveEntry(\ )
  3081. .)x \*($n
  3082. .lp
  3083. Sm_RemoveEntry(\ ) removes a <key, elem> pair from the index \*(lqndx\*(rq. 
  3084. .br
  3085. .sh 3 "Loading Indexes in Bulk"
  3086. .lp
  3087. The Storage Manager provides a bulk-load facility for 
  3088. efficiently loading an empty index.
  3089. When the application begins a bulk-load operation,
  3090. the client library 
  3091. allocates a temporary run-buffer, which is used for sorting runs.  
  3092. Henceforth, the application uses sm_InsertEntry(\ ) 
  3093. repeatedly to load elements into index; no other
  3094. index operations are allowed during a bulk-load.  
  3095. Each sm_InsertEntry(\ ) operation
  3096. for the index inserts a <key, elem> pair into the 
  3097. temporary run buffer. 
  3098. The run buffer is sorted and written to the work file as 
  3099. a \*(lqsorted-run\*(rq when it is full. 
  3100. When the application terminates the bulk-load operation,
  3101. the client library 
  3102. merges the sorted-runs into a sorted stream, from 
  3103. which the index is built from the bottom, up.
  3104. .lp
  3105. Entries cannot be removed during a bulk-load operation.
  3106. .sp 2
  3107. .(b L
  3108. \fBint sm_BeginIndexLoad(ndx, groupIndex, workVolume, runSize)
  3109. IID*            ndx;            /* IN index identifier */
  3110. int            groupIndex;        /* IN the buffer group to use */
  3111. VOLID        workVolume;        /* IN work volume */
  3112. int            runSize;        /* IN size of each sorted run in pages */ \fR
  3113. .)b
  3114. Sm_BeginIndexLoad(\ ) prepares to load the index given in \*(lqndx\*(rq,
  3115. using the buffer group \*(lqgroupIndex\*(rq.
  3116. Sm_BeginIndexLoad(\ ) uses the volume named by
  3117. \*(lqworkVolume\*(rq for the sorted runs. 
  3118. Using a temporary volume for the work volume yields
  3119. .(x z
  3120. temporary volume
  3121. .)x \*($n
  3122. the best performance
  3123. (see Section 5.1.3, \fBTemporary Volumes\fR).
  3124. .lp
  3125. The \*(lqrunSize\*(rq argument determines how many MIN_PAGESIZE pages 
  3126. to fill before ending a run. 
  3127. The larger \*(lqrunSize\*(rq, the 
  3128. more memory is consumed by the bulk-load, with a commensurate
  3129. improvement in speed.
  3130. Sm_BeginIndexLoad(\ ), if it is used,  must be the first operation performed on 
  3131. an index.
  3132. .sp 2
  3133. .(b L
  3134. \fBint sm_EndIndexLoad(ndx)
  3135. IID*             ndx;            /* IN index identifier */ \fR
  3136. .)b
  3137. Sm_EndIndexLoad(\ ) concludes the bulk-load and builds the index.
  3138. .sp
  3139. .(b L 2
  3140. \fBint sm_AbortIndexLoad(ndx)
  3141. IID*             ndx;            /* IN index identifier */ \fR
  3142. .)b
  3143. sm_AbortIndexLoad(\ ) aborts the bulk-loading of an index. 
  3144. All resources used by the index are freed.
  3145. .br
  3146. .sh 3 "Scanning Indexes"
  3147. .lp
  3148. Indexes are used by posing queries with the sm_FetchInit(\ ) operation. 
  3149. A query requests all the elements whose key values lie in a range.
  3150. The results of the query are fetched, one element at a time, with the
  3151. sm_FetchNext(\ ) operation.
  3152. An index scan uses a \fIcursor\fR, a value of the type SMCURSOR.
  3153. .(x z
  3154. cursor
  3155. .)x \*($n
  3156. A cursor can be treated by the application as an opaque value.
  3157. The following two macros give a cursor an invalid
  3158. initial value and recognize that value:
  3159. .(b I
  3160. \fBINVALIDATE_CURSOR (SMCURSOR cursor)\fR 
  3161. .)b
  3162. sets \*(lqcursor\*(rq to an invalid index scan cursor.
  3163. .(b I
  3164. \fBCURSOR_IS_INVALID (SMCURSOR cursor)\fR 
  3165. .)b
  3166. returns TRUE if \*(lqcursor\*(rq is the value given
  3167. by INVALIDATE_CURSOR(\ ), FALSE if not.
  3168. .lp
  3169. The rest of this section describes the functions used to scan 
  3170. indexes.
  3171. .sp
  3172. .(b L
  3173. \fBsm_FetchInit(ndx, groupIndex, bound1, cond1, bound2, cond2, cursor)
  3174. IID*            ndx;            /* IN index identifier */
  3175. int            groupIndex;        /* IN which buffer group to use */
  3176. KEY*            bound1;        /* IN starting bound of the scan */
  3177. SMCOND        cond1;            /* IN starting condition */
  3178. KEY*            bound2;        /* IN ending bound of the scan */
  3179. SMCOND        cond2;            /* IN ending condition */
  3180. SMCURSOR*    cursor;        /* OUT returned pointer if non-NULL */\fR
  3181. .)b
  3182. .(x z
  3183. scanning an index
  3184. .)x \*($n
  3185. .(x z
  3186. index scan
  3187. .)x \*($n
  3188. .(x z
  3189. sm_FetchInit(\ )
  3190. .)x \*($n
  3191. .lp
  3192. Sm_FetchInit(\ ) begins a scan on the index \*(lqndx\*(rq. 
  3193. The arguments \*(lqbound1\*(rq and \*(lqcond1\*(rq specify the 
  3194. beginning search condition.
  3195. \*(lqBound2\*(rq and \*(lqcond2\*(rq specify the ending search condition.  
  3196. The conditions can be  SM_EQ, SM_G, SM_L, SM_GEQ, or SM_LEQ.
  3197. The \*(lqcursor\*(rq argument is initialized by 
  3198. sm_FetchInit(\ ) and used by sm_FetchNext(\ ).
  3199. The caller is responsible for allocating the space for the cursor
  3200. and the client library is responsible for the value of the cursor.
  3201. .sp
  3202. The direction of the scan (ascending or descending) is 
  3203. determined by the bounds and conditions of the query. 
  3204. The beginning and end of an index are specified with the
  3205. macros SM_BOF and SM_EOF.
  3206. For linear hashing indexes (type SM_HASHNDX), the value that
  3207. .(x z
  3208. index query
  3209. .)x \*($n
  3210. .(x z
  3211. query, index
  3212. .)x \*($n
  3213. can be used for \*(lqcond1\*(rq and \*(lqcond2\*(rq is SM_EQ.
  3214. .sp
  3215. Several examples of queries follow:
  3216. .np 
  3217. Scan from key1 = \*(lq10\*(rq to key2 = \*(lq30\*(rq inclusively:
  3218. .br
  3219. sm_FetchInit( ..., key1, SM_GEQ, key2, SM_LEQ, cursor) --- ascending 
  3220. .br
  3221. sm_FetchInit( ..., key2, SM_LEQ, key1, SM_GEQ, cursor) --- descending
  3222. .sp
  3223. .np 
  3224. Scan from key1 = \*(lq10\*(rq to the end of the index:
  3225. .br
  3226. sm_FetchInit( ..., key1, SM_GEQ, SM_EOF, cursor) --- ascending
  3227. .br
  3228. sm_FetchInit( ..., SM_EOF, key1, SM_GEQ, cursor) --- descending
  3229. .sp
  3230. .np 
  3231. Scan the whole index:
  3232. .br
  3233. sm_FetchInit( ..., SM_BOF, SM_EOF, cursor) --- ascending
  3234. .br
  3235. sm_FetchInit( ..., SM_EOF, SM_BOF, cursor) --- descending
  3236. .lp
  3237. .sp 2
  3238. .(b L
  3239. \fBsm_FetchNext(cursor, retKey, retElem, eof)
  3240. SMCURSOR*    cursor;        /* IN cursor from sm_Fetch(\ ) */
  3241. KEY*            retKey;        /* OUT returned key (optional) */
  3242. void*             retElem;        /* OUT elem */
  3243. BOOL*        eof;            /* OUT to TRUE if EOF reached */\fR
  3244. .)b
  3245. .(x z
  3246. sm_FetchNext(\ )
  3247. .)x \*($n
  3248. .lp
  3249. Sm_FetchNext(\ ) fetches the next element returned by a query.
  3250. The element is returned in the structure addressed by \*(lqretElem\*(rq.
  3251. A copy of the key can also be returned to the caller.
  3252. If \*(lqretKey\*(rq is NULL, no key is returned.
  3253. If \*(lqretKey\*(rq points to a key structure, the key is returned in that
  3254. structure.
  3255. The \*(lqlength\*(rq field in the key structure must indicate
  3256. amount of space available in the 
  3257. target of the \*(lqvaluePtr\*(rq field.
  3258. This must be enough for the longest key in the index.  
  3259. The caller is responsible for allocating space for \*(lqretKey\*(rq and \*(lqretElem\*(rq.  
  3260. .lp
  3261. sm_FetchNext(\ ) returns FALSE in \*(lqeof\*(rq if an element is returned.
  3262. If there are no more elements that satisfy the query,
  3263. TRUE is returned in \*(lqeof\*(rq.
  3264. .sp
  3265. .br
  3266. .sh 2 "Advanced Topics"
  3267. .sh 3 "External Two-Phase Commit Functions"
  3268. .(x z
  3269. two-phase commit functions, external
  3270. .)x \*($n
  3271. .(x z
  3272. two-phase commit protocol, external
  3273. .)x \*($n
  3274. .(x z
  3275. transactions, distributed
  3276. .)x \*($n
  3277. .(x z
  3278. distributed transactions
  3279. .)x \*($n
  3280. .lp
  3281. The Storage Manager can particpate in transactions coordinated by 
  3282. other software modules  that employ the 
  3283. two-phase commit \*(lqpresumed abort\*(rq transaction semantics and protocol.
  3284. (For the purpose of this section, the reader is assumed to be familiar
  3285. with the \*(lqpresumed abort\*(rq protocol.)
  3286. The coordinator in such a situation is external to the Storage Manager;
  3287. it is assumed to have its own stable storage, and it is assumed
  3288. to recover from failures in a \fIshort time\fR (the precise meaning
  3289. of which is given forthwith).
  3290. .lp
  3291. A prepared transaction, like an active transaction, consumes log space on
  3292. one or more Exodus servers, 
  3293. beginning at a fixed location in each log.
  3294. A Storage Manager server's log is like a circular buffer; it
  3295. wraps and reuses the beginning of the log.
  3296. If long-running or prepared transactions are still in the system,
  3297. the server eventually tries to re-use log space 
  3298. consumed by the oldest transaction, at which point it 
  3299. effectively runs out of log space.
  3300. A coordinator must resolve its prepared transactions before the servers
  3301. run out of log space.  The amount of time involved is a function of
  3302. the size of the log on the participating servers and the load on those
  3303. servers.
  3304. .lp
  3305. For the purpose of this discussion,
  3306. the portion of a global transaction that involves a single
  3307. Exodus Storage Manager transaction is called a \fIthread\fR
  3308. .(x z
  3309. thread
  3310. .)x \*($n
  3311. of the global transaction.
  3312. Each thread has, in addition to its
  3313. local transaction identifier, a global transaction identifier.
  3314. Global transaction identifiers are provided by the application or
  3315. some external authority, and must be unique.
  3316. A global transaction identifier has type GTID, defined in 
  3317. \fCsm_client.h\fR, as follows:
  3318. .(b I
  3319. \fB#define MAXOPAQUELEN 255
  3320. \fBtypedef struct {
  3321.        int        length;     /* maximum MAXOPAQUELEN bytes */
  3322.        u_char    opaque[MAXOPAQUELEN]; 
  3323. } GTID;
  3324. .)b
  3325. .(x z
  3326. transaction identifier, global
  3327. .)x \*($n
  3328. .(x z
  3329. global transaction identifier
  3330. .)x \*($n
  3331. .(x z
  3332. GTID
  3333. .)x \*($n
  3334. .lp
  3335. The Storage Manager does not interpret the contents of the opaque
  3336. part of the global transaction identifier.
  3337. .lp
  3338. An application that invokes the external two-phase commit protocol can find
  3339. itself in any of the transaction states mentioned in
  3340. Section 4.3.2 (\*(lqTransaction States\*(rq).
  3341. It can also find itself in the PREPARED state
  3342. after a call to sm_PrepareTransaction(\ ).
  3343. An application in PREPARED state calls 
  3344. sm_CommitTransaction(\ ) or sm_AbortTransaction(\ )
  3345. to complete the transaction and return to the INACTIVE state.
  3346. .lp
  3347. While the coordinator for a global transaction is external to 
  3348. the Storage Manager, a single Storage Manager server corresponds with
  3349. the client library and coordinates 
  3350. the Storage Manager servers that participate in the thread.
  3351. If the application should crash during a two-phase commit,
  3352. a new application program (representing the global coordinator)
  3353. must run, and it must contact the Storage Manager that is acting
  3354. as the thread's coordinator.
  3355. In order to locate the proper server, a
  3356. two-phase commit process begins by 
  3357. informing the client library that a transaction is a thread
  3358. of a global transaction, and by identifying the thread's coordinator.
  3359. The function sm_Enter2PC(\ ), described below, accomplishes this.
  3360. .sp
  3361. .(b L
  3362. \fBsm_Enter2PC (tid, gtid, handle)
  3363. TID        tid;            /* IN transaction ID */
  3364. GTID        *gtid;            /* IN global transaction ID */
  3365. COORD_HANDLE    *handle;    /* OUT for use if client crashes */
  3366. \fR
  3367. .)b
  3368. .(x z
  3369. sm_Enter2PC(\ )
  3370. .)x \*($n
  3371. .lp
  3372. The application supplies the local and global transaction identifiers.
  3373. The client library identifies a thread coordinator, and produces
  3374. a handle for the application to write to stable storage.
  3375. The handle identifies the thread coordinator; it is used
  3376. by sm_Recover2PC(\ ) if the client crashes before the two-phase
  3377. commit is completed.
  3378. .lp
  3379. The handle must be written to stable storage before the 
  3380. first phase of the commit begins, 
  3381. otherwise the application and Storage Manager
  3382. may not be able to recover from a subsequent application failure.
  3383. .sp
  3384. .(b L
  3385. \fBsm_PrepareTransaction (tid, vote)
  3386. TID        tid;            /* IN transaction ID */
  3387. VOTE        *vote;            /* OUT result of first phase */
  3388. \fR
  3389. .)b
  3390. .(x z
  3391. sm_PrepareTransaction(\ )
  3392. .)x \*($n
  3393. .lp
  3394. The application calls sm_PrepareTransaction(\ ) to begin the first, or
  3395. prepare, phase of a two-phase commit.
  3396. sm_PrepareTransaction(\ ) determines if
  3397. the participating servers are able to commit the transaction, 
  3398. and directs them to prepare to commit if they are.
  3399. If any of the participating servers is unable to commit the
  3400. transaction, the vote returned is NOVOTE,
  3401. sm_PrepareTransaction(\ ) sets sm_error to esmTRANSABORTED, 
  3402. sm_reason to esmTRANSNOTPREPARED, 
  3403. and returns esmFAILURE; 
  3404. the application must call sm_AbortTransaction(\ ).
  3405. .lp
  3406. If all participating servers are able to commit, and any of them
  3407. logged updates during the transaction, the vote is YESVOTE, 
  3408. and 
  3409. the transaction state becomes PREPARED.
  3410. If the transaction did not update any data on any of the servers,
  3411. the vote is READVOTE, and the transaction state becomes INACTIVE.
  3412. Sm_PrepareTransaction(\ ) returns esmNOERROR if the transaction
  3413. becomes prepared (all servers vote YESVOTE) or committed 
  3414. (all server vote READVOTE).
  3415. .lp
  3416. If an error occurs during the prepare phase,
  3417. sm_PrepareTransaction(\ ) returns esmFAILURE.
  3418. If it is a recoverable error, 
  3419. the client library returns an error code specific to the error
  3420. in sm_errno (such as esmTRANSDISABLED if a server is performing recovery),
  3421. and the application
  3422. can try again to call sm_PrepareTransaction(\ ).
  3423. Some errors, on the other hand, cause the transaction to be aborted,
  3424. in which case sm_PrepareTransaction(\ ) returns esmTRANSABORTED in 
  3425. sm_errno, and a vote of NOVOTE.
  3426. .(x z
  3427. vote, two-phase commit
  3428. .)x \*($n
  3429. .(x z
  3430. esmTRANSABORTED
  3431. .)x \*($n
  3432. .lp
  3433. If an application crashes during the first phase, the application
  3434. must retry the prepare phase and complete the transaction.
  3435. If it does not retry the prepare phase, and 
  3436. the transaction was indeed prepared before the
  3437. application crashed, 
  3438. the prepared transaction consumes resources indefinitely, 
  3439. and eventually its servers will run out of log space.
  3440. .lp
  3441. Once a transaction is prepared, an application must invoke the
  3442. second phase by aborting or committing
  3443. the transaction
  3444. (calling sm_AbortTransaction(\ ) or sm_CommitTransaction(\ ), respectively).
  3445. It is an error to commit a global transaction thread 
  3446. without first preparing the transaction, and it is an error
  3447. to do anything else without completing the second phase. 
  3448. .lp
  3449. When an error occurs during the second phase, the application cannot
  3450. tell if the second phase completed (the transaction indeed committed
  3451. or aborted).  
  3452. It is alway safe to try again to complete the transaction
  3453. by calling sm_AbortTransaction(\ ) or sm_CommitTransaction(\ ) again.
  3454. .lp
  3455. If the second phase fails because the network connection between
  3456. the client and the thread coordinator breaks 
  3457. (esmSERVERDIED or esmNOTCONNECTED), the
  3458. client must reconnect to the thread coordinator before the second
  3459. phase can be finished.
  3460. The following function does that:
  3461. .sp
  3462. .(b L
  3463. \fBsm_Continue2PC (tid, willing2block)
  3464. TID        tid;            /* IN transaction ID */
  3465. BOOL        willling2block;    /* IN ok to block indefinitely */
  3466. .)b
  3467. .(x z
  3468. sm_Continue2PC(\ )
  3469. .)x \*($n
  3470. .lp
  3471. If \*(lqwilling2block\*(rq is TRUE, 
  3472. the client library blocks until it connects to the thread
  3473. coordinator.
  3474. If this is inappropriate for the application, \*(lqwilling2block\*(rq
  3475. must be FALSE, and the client library tries once to contact
  3476. the thread coordinator.
  3477. .lp
  3478. If the application crashes, its replacement
  3479. must use sm_Recover2PC(\ ), below, instead of sm_Continue2PC(\ ) to 
  3480. resolve the transaction.
  3481. .sp
  3482. .(b L
  3483. \fBsm_Recover2PC (gtid, handle, willing2block, tid)
  3484. COORD_HANDLE    *handle;        /* IN handle for thread coordinator */
  3485. GTID            *gtid;            /* IN global transaction ID */
  3486. BOOL            willing2block;    /* IN ok to block indefinitely */
  3487. TID            *tid;            /* OUT local transaction ID */\fR
  3488. .)b
  3489. .(x z
  3490. sm_Recover2PC(\ )
  3491. .)x \*($n
  3492. .lp
  3493. When the application crashes (exits) after a transaction
  3494. is prepared but before its second phase is completed,
  3495. a \*(lqrecovery\*(rq application program must be run within a short time
  3496. to finish the two-phase commit and resolve the transaction.
  3497. This recovery application must use sm_Recover2PC(\ ), supplying
  3498. the global transaction identifier and
  3499. the handle returned by sm_Enter2PC(\ ) for that global transaction. 
  3500. The client library contacts the server identified in the handle,
  3501. which conveys to the client library all that is needed for the
  3502. application to enter or to retry the second phase.
  3503. The transaction's local transaction identifier is 
  3504. returned by sm_Recover2PC(\ )
  3505. for the application to use in its subsequent call to
  3506. sm_CommitTransaction(\ ) or sm_AbortTransaction(\ ).
  3507. .lp
  3508. The thread coordinator may not be available, in which case the
  3509. client library keeps trying to connect or it will
  3510. return an error (such as ECONNREFUSED), depending on the value
  3511. of \*(lqwilling2block\*(rq.  
  3512. If \*(lqwilling2block\*(rq is FALSE, the client library tries only once
  3513. to connect the thread coordinator.
  3514. .br
  3515. .sh 3 "Administrative Operations"
  3516. .lp
  3517. The following functions can be applied to one or more
  3518. servers.  
  3519. Each function takes two arguments that determine which
  3520. servers are of interest.  
  3521. The first argument is of type FLAGS, and takes one of the
  3522. following values:
  3523. .sp
  3524. .(b
  3525. \fRVOL_ALL    /* the servers for all volumes */    
  3526. VOL_USED_SINCE_INIT    /* servers for all volumes used */    
  3527. VOL_USED_IN_TRANSACTION    /* servers used in this transaction  */    
  3528. VOL_BY_VOLID    /* the second argument applies */
  3529. .)b
  3530. The client library keeps a list of volumes and the
  3531. servers that manage those volumes.
  3532. The list is created from the information given in the
  3533. configuration files and information passed to the library
  3534. .(x z
  3535. configuration files
  3536. .)x \*($n
  3537. through sm_SetClientOption(\ ), 
  3538. The flag VOL_ALL 
  3539. directs the client library to apply 
  3540. the administrative operation to 
  3541. the server that manages each volume in its list of known volumes.
  3542. The flag VOL_USED_SINCE_INIT 
  3543. directs the client library to apply the administrative operation to 
  3544. each server contacted since sm_Initialize(\ ) was called.
  3545. The flag VOL_USED_IN_TRANSACTION
  3546. directs the client library to apply the administrative operation to 
  3547. each server contacted so far for participation in the current transaction.
  3548. (It does not apply to servers to be contacted for the
  3549. first time later in the transaction.)
  3550. The flag VOL_BY_VOLID 
  3551. directs the client library to apply the administrative operation to 
  3552. the server that manages the volume identified by the 
  3553. second argument.
  3554. The second argument is a volume identifier VOLID, which is ignored
  3555. when the flags argument is VOL_ALL, VOL_USED_SINCE_INIT,  or 
  3556. VOL_USED_IN_TRANSACTION.
  3557. .lp
  3558. Ideally the administrative operations would 
  3559. only be performed by trusted clients, 
  3560. but the Storage Manager does not restrict their use.
  3561. .sp
  3562. .(b L
  3563. \fBsm_TakeCheckpoint (flags,  volid, numCheckpoints)
  3564. FLAGS        flags;            /* IN which servers are of interest */
  3565. VOLID        volid;            /* IN which server is of interest */
  3566. short            numCheckpoints;    /* IN number of checkpoints to take */\fR
  3567. .)b
  3568. .(x z
  3569. sm_TakeCheckpoint(\ )
  3570. .)x \*($n
  3571. .lp
  3572. Sm_TakeCheckpoint(\ ) sends a request to the server to take a 
  3573. number of checkpoints.  
  3574. In most circumstances, a value of 
  3575. one for the \*(lqnumCheckpoints\*(rq argument is appropriate.  
  3576. A value greater than 1 can be used to ensure
  3577. that the server flushes all pages that were dirty when the first
  3578. checkpoint was taken.  
  3579. (This is useful for experimenting with the recovery facility).
  3580. .sp
  3581. .(b L
  3582. \fBsm_ChangeCheckpointFrequency (flags, volid, frequency)
  3583. FLAGS        flags;            /* IN which servers are of interest */
  3584. VOLID        volid;            /* IN which server is of interest */
  3585. int            frequency;        /* IN number of log records between checkpoints */\fR
  3586. .)b
  3587. .(x z
  3588. sm_ChangeCheckpointFrequency(\ )
  3589. .)x \*($n
  3590. .lp
  3591. Sm_ChangeCheckpointFrequency(\ ) changes 
  3592. the frequency of checkpoints taken by the server.  
  3593. The checkpoint frequency is based on the
  3594. number of log pages written.
  3595. .(x z
  3596. checkpoint frequency, changing
  3597. .)x \*($n
  3598. .(x z
  3599. default checkpoint frequency
  3600. .)x \*($n
  3601. More information about checkpoint frequency can be found in 
  3602. Section 5.3, \fBTuning the Server\fR.
  3603. .sp
  3604. .(b L
  3605. \fBsm_ShutdownServer (flags, volid, options)
  3606. FLAGS        flags;            /* IN which servers are of interest */
  3607. VOLID        volid;            /* IN which server is of interest */
  3608. FLAGS        options;        /* IN shutdown options */\fR
  3609. .)b
  3610. .(x z
  3611. sm_ShutdownServer(\ )
  3612. .)x \*($n
  3613. .lp
  3614. Sm_ShutdownServer(\ ) directs servers to shut down.  
  3615. The \*(lqoptions\*(rq argument indicates what a server should do before exiting.  
  3616. The following flags are available:  NOFLAGS,
  3617. SHUT_TAKE_CHECKPOINT, SHUT_DUMP_CORE, SHUT_ABORT_TRANS,
  3618. SHUT_COMMIT_TRANS, SHUT_CLEAN_VOLUMES.  
  3619. These can be combined with the logical \*(lqor\*(rq operator.  
  3620. .lp
  3621. If NOFLAGS is given, the server 
  3622. kills the disk processes and exits.  
  3623. .lp
  3624. SHUT_TAKE_CHECKPOINT directs the server to take a checkpoint before exiting.  
  3625. .lp
  3626. SHUT_DUMP_CORE directs the server to dump a core file debugging (see core(5)).
  3627. .lp
  3628. SHUT_COMMIT_TRANS directs the server to wait until the 
  3629. running transactions 
  3630. either commit or abort before it shuts down.
  3631. .lp
  3632. SHUT_ABORT_TRANS directs the server to abort all running transactions 
  3633. before shutting down.
  3634. When SHUT_COMMIT_TRANS or SHUT_ABORT_TRANS is used, clients 
  3635. cannot start any new transactions.  
  3636. .lp
  3637. SHUT_CLEAN_VOLUMES directs the server to
  3638. write dirty pages to disk before exiting.
  3639. To shut down a server after which recovery is not required, 
  3640. use either
  3641. SHUT_COMMIT_TRANS | SHUT_CLEAN_VOLUMES or
  3642. SHUT_ABORT_TRANS | SHUT_CLEAN_VOLUMES.
  3643. .sp
  3644. .(b L
  3645. \fBsm_ServerStatistics (flags, volid, numServers, stats, reset)
  3646. FLAGS        flags;            /* IN which servers are of interest */
  3647. VOLID        volid;            /* IN which server is of interest */
  3648. int            *numServers;    /* OUT # servers contacted */
  3649. SERVERSTATS    **stats;        /* OUT servers' statistics */
  3650. BOOL            reset;            /* IN TRUE = reinitialize counters */\fR
  3651. .)b
  3652. .(x z
  3653. sm_ServerStatistics(\ )
  3654. .)x \*($n
  3655. .lp
  3656. Sm_ServerStatistics(\ ) 
  3657. obtains statistics about one or more servers.  
  3658. For each server contacted, a set of statistics is returned.
  3659. The client library allocates space for the statistics, and the 
  3660. \fBapplication is responsible for freeing that space\fR
  3661. ( see the manual page for malloc(3) ).
  3662. The \*(lqflags\*(rq indicate which servers are of interest,
  3663. and the number of servers contacted is returned in
  3664. \*(lq*numServers\*(rq.
  3665. On return from sm_ServerStatistics(\ ),
  3666. the \*(lq*stats\*(rq pointer addresses an array of
  3667. \*(lq*numServers\*(rq SERVERSTATS structures.
  3668. This array must be freed by the application with one call to
  3669. \fIfree(3)\fR.
  3670. .lp
  3671. If \*(lqreset\*(rq is TRUE, the statistics labeled as counters below are
  3672. reset to zero.  
  3673. .lp
  3674. The SERVERSTATS structure looks like this:
  3675. .(b I
  3676. \fBtypedef struct {
  3677.        int        numClients;        /* # clients connected */
  3678.        int        numTrans;        /* # transactions in progress */
  3679.        int        numVolumes;        /* # volumes mounted */
  3680.        int        freeLogSpace;    /* approximate # bytes free log space */
  3681.        int        chpntFreq;        /* checkpoint frequency */
  3682.        int        totalCommits;    /* # transactions committed */
  3683.        int        totalAborts;        /* # transactions aborted */
  3684.        int        diskReads;        /* # disk reads */
  3685.        int        diskWrites;        /* # disk writes */
  3686.        MESSAGESTATS    msgStats;    /* server's message counters */
  3687. } SERVERSTATS;
  3688. .)b
  3689. .(x z
  3690. MESSAGESTATS
  3691. .)x \*($n
  3692. .(x z
  3693. SERVERSTATS
  3694. .)x \*($n
  3695. .lp
  3696. The MESSAGESTATS structure contains statistics about
  3697. the client-server protocol and the server-server protocol.
  3698. A set of these statistics is kept by the client library 
  3699. a set is kept by each server.
  3700. The client library's statistics are found in the global
  3701. structure
  3702. .(b L
  3703. \fBextern MESSAGESTATS MsgStats;\fR
  3704. .)b
  3705. The MESSAGESTATS structure contains the following counters 
  3706. for each message type: messages sent, messages received,
  3707. replies received with an error indication,
  3708. replies received with no error,
  3709. messages sent with no reply requested.
  3710. The counters for replies have two different meanings, depending 
  3711. on which set statistics is concerned.
  3712. The servers count the replies \fIsent\fR 
  3713. with and without error
  3714. indications, and the number of requests that the
  3715. server \fIreceived\fR that did not require a reply at all.
  3716. The client library counts the replies \fIreceived\fR
  3717. with and without error indications, and the number of requests that the
  3718. client \fIsent\fR that did not require a reply at all.
  3719. .lp
  3720. The following function
  3721. prints the MESSAGESTATS structure:
  3722. .sp
  3723. .(b L
  3724. \fBsm_PrintMessageStats (file, stats)
  3725. FILE            *const        file;            /* IN where to print */
  3726. MESSAGESTATS    *const        msgStats;        /* IN what to print */
  3727. .)b
  3728. .(x z
  3729. sm_PrintMessageStats(\ )
  3730. .)x \*($n
  3731. .lp
  3732. The following function tells if a mounted volume is
  3733. temporary volume, a data volume, or a log volume.
  3734. .(x z
  3735. temporary volume
  3736. .)x \*($n
  3737. See 
  3738. Section 5.1, \fBManaging Volumes\fR, for information
  3739. about volumes.
  3740. .sp
  3741. .(b L
  3742. \fBsm_VolumeProperties (volid, properties)
  3743. VOLID        volid;            /* IN which volume is of interest */
  3744. int            *properties;        /* OUT the properties */
  3745. .)b
  3746. .(x z
  3747. sm_VolumeProperties(\ )
  3748. .)x \*($n
  3749. .lp
  3750. Sm_VolumeProperties(\ ) returns a set of bits
  3751. that tell whether the given volume is a data 
  3752. volume or a temporary volume.
  3753. The \*(lqvolid\*(rq argument is the volume identifier of
  3754. the volume in question.
  3755. If the volume is not mounted when Sm_VolumeProperties(\ )
  3756. is called,  Sm_VolumeProperties(\ ) mounts it.
  3757. .lp
  3758. VOLPROP_TEMP indicates that the volume is temporary
  3759. .(x z
  3760. temporary volume
  3761. .)x \*($n
  3762. (see 
  3763. Section 5.1.3, \fBTemporary Volumes\fR).
  3764. If the bit VOLPROP_TEMP is not set in the result,
  3765. the volume is a data volume.
  3766. A log volume cannot be mounted by a client, and
  3767. an attempt to get a log volume's properties results
  3768. in an error.
  3769. .sp
  3770. .(b L
  3771. \fBsm_AddServerVolume (flags, volid, option, value)
  3772. FLAGS        flags;            /* IN which servers are of interest */
  3773. VOLID        volid;            /* IN which volume is of interest */
  3774. char        *option;            /* IN which format option to use */
  3775. char        *value;            /* IN value for the format option */
  3776. .)b
  3777. .(x z
  3778. sm_AddServerVolume(\ )
  3779. .)x \*($n
  3780. .lp
  3781. Sm_AddServerVolume(\ ) adds a volume to the list of mountable volumes
  3782. on one or more servers
  3783. (although it seldom makes sense to do this on more than one server
  3784. with a single pair of arguments).
  3785. The \*(lqflags\*(rq argument indicates which servers are of interest.
  3786. The \*(lqvolid\*(rq argument is the volume identifier of
  3787. the volume that will determine which server to contact when
  3788. \*(lqflags\*(rq == VOL_BY_VOLID.
  3789. The \*(lqoption\*(rq is one of 
  3790. the server's format options
  3791. (\*(lqdataformat\*(rq or \*(lqtempformat\*(rq).
  3792. The \*(lqvalue\*(rq
  3793. argument is the value to be given the option named in \*(lqoption\*(rq.
  3794. .lp
  3795. Sm_AddServerVolume(\ ) adds the named volume to the server's list
  3796. of known volumes, but the server does not try to mount the volume
  3797. or verify that the volume exists or is valid.
  3798. Sm_AddServerVolume(\ ) fails
  3799. if the value given conflicts with
  3800. another volume already in the server's table, 
  3801. either in the path name or the volume identifier.
  3802. If your objective is to change the format information
  3803. for a path name that is in the server's table, 
  3804. first remove the existing format information 
  3805. (using sm_RemoveServerVolume(\ ), described below),
  3806. and subsequently add the new information.
  3807. .sp
  3808. .(b L
  3809. \fBsm_RemoveServerVolume (flags, volid, volid2remove)
  3810. FLAGS        flags;            /* IN which servers are of interest */
  3811. VOLID        volid;            /* IN which volume id of server of interest */ 
  3812. VOLID        volid2remove;    /* IN which volume to remove */
  3813. .)b
  3814. .(x z
  3815. sm_RemoveServerVolume(\ )
  3816. .)x \*($n
  3817. .lp
  3818. Sm_RemoveServerVolume(\ ) removes 
  3819. \*(lqvolid2remove\*(rq from one or more  servers' lists of mountable volumes.
  3820. The volume cannot be removed from a server's table while the volume
  3821. is in use. 
  3822. it must be dismounted before it is removed.
  3823. .lp
  3824. See also
  3825. Section 5.1, \fBManaging Volumes\fR.
  3826. .br
  3827. .sh 3 "Tuning the Application"
  3828. .lp
  3829. The size of the application's buffer pool, 
  3830. determined by the \*(lqbufpages\*(rq option,
  3831. is the primary tuning parameter that 
  3832. is under the control of applications.  
  3833. The \*(lqbufpages\*(rq option indicates the number of 
  3834. MIN_PAGESIZE
  3835. pages in the buffer pool. 
  3836. It should be set large enough
  3837. to hold the application's working set of objects.
  3838. The buffer pool must not exceed the size of physical memory available to 
  3839. the client.
  3840. .bp
  3841. .sh 1 "USING STORAGE MANAGER SERVERS"
  3842. .lp
  3843. Storage Manager servers provide disk, file, transaction,
  3844. concurrency control, and recovery services to clients.
  3845. In most respects, users do not have to understand how servers
  3846. work, but there are a few things that administrators should know;
  3847. we focus on those things in this section.  
  3848. The first half of this section explains how to manage volumes.  
  3849. The second half explains how to operate a server.
  3850. .sp
  3851. .sh 2 "Managing Volumes"
  3852. .lp
  3853. Servers store data on \fIvolumes\fR,
  3854. .(x z
  3855. volume
  3856. .)x \*($n
  3857. .(x z
  3858. files, Unix
  3859. .)x \*($n
  3860. .(x z
  3861. partition
  3862. .)x \*($n
  3863. which can be Unix files or raw disk partitions.  
  3864. Each server is composed of a server process 
  3865. and one \fIdisk process\fR for each mounted volume.  
  3866. .(x z
  3867. disk process
  3868. .)x \*($n
  3869. When a server requires I/O, it asks the appropriate disk
  3870. process to read from or write to the server's buffer pool, which
  3871. is located in a Unix System V shared-memory segment.  
  3872. The disk processes perform I/O so 
  3873. that the server never blocks when I/O is required. 
  3874. The server mounts a volume before using it, and the server
  3875. dismounts the volume when it is no longer in use.
  3876. Mounting a volume consists in forking a disk process for that volume.
  3877. Dismounting the volume consists in flushing all dirty pages to the disk
  3878. and killing the volume's disk process.
  3879. .lp
  3880. Volumes are created with the \fCformatvol\fR program, which
  3881. establishes a volume's identifier, size, type, and other characteristics.
  3882. Volumes come in three types: log volumes, data volumes, and temporary volumes.
  3883. .(x z
  3884. temporary volume
  3885. .)x \*($n
  3886. .sh 3 "Log Volumes"
  3887. .lp
  3888. Log volumes are used to store log information for 
  3889. aborting transactions and for recovery.  
  3890. The server has one log volume mounted at all times.
  3891. .sh 3 "Data Volumes"
  3892. .lp
  3893. Data volumes are used to store objects and indexes
  3894. that are meant to exist after a transaction ends.
  3895. Changes to data volumes are logged so that transactions
  3896. can be aborted or committed with reliability, and
  3897. so that recovery can be performed after a crash.
  3898. .sh 3 "Temporary Volumes"
  3899. .lp
  3900. Some applications store temporary private data 
  3901. and do not need concurrency control or recovery. 
  3902. The Storage Manager provides temporary volumes for this purpose.  
  3903. .(x z
  3904. temporary volume
  3905. .)x \*($n
  3906. Locks are not acquired for data in temporary volumes,
  3907. and updates to temporary volumes are not logged. 
  3908. Temporary volumes are less costly to use than data volumes are,
  3909. but the data on them cannot be shared among transactions.
  3910. The data on temporary volumes are deleted at the conclusion
  3911. of the transaction that creates them, regardless of
  3912. whether the transaction is committed or aborted.
  3913. Temporary volumes cannot contain root entries.
  3914. .lp
  3915. The server can serve many data volumes and 
  3916. temporary volumes simultaneously.
  3917. .sh 3 "Raw Partitions and Unix Files"
  3918. .lp
  3919. A volume can be a Unix file or a Unix raw partition.
  3920. When a raw partition is used,
  3921. data are transferred between the server's buffer pool and the disk
  3922. by the disk process, bypassing the Unix file system's buffer pool.
  3923. .lp
  3924. When a Unix file is used, the data are written to the Unix
  3925. file system's buffer pool, and the operating system worries about
  3926. flushing the data to the disk.
  3927. In this case,
  3928. the server forces the data to the disk periodically with
  3929. a Unix \fIfsync(\ )\fR system call.
  3930. .br
  3931. .sh 3 "Formatting Volumes"
  3932. .lp
  3933. Before a volume can be used, it must be formatted.  
  3934. This is done using the \fCformatvol\fR program, which can also
  3935. display information about previously formatted volumes.
  3936. Formatvol uses  
  3937. .(x z
  3938. configuration options
  3939. .)x \*($n
  3940. the configuration options  
  3941. \*(lqdataformat\*(rq,
  3942. \*(lqtempformat\*(rq, and 
  3943. \*(lqlogformat\*(rq
  3944. to determine what characteristics to give volumes that it formats.
  3945. The options have values that list the following
  3946. information:
  3947. .ip "path" 10
  3948. The Unix path name of the volume, e.g., \fC/dev/rz2c\fR.
  3949. .ip "volid" 10
  3950. The volume identifier for this volume, an integer, e.g., 8000.
  3951. .ip "#cyl" 10
  3952. The number of cylinders on this disk, e.g., 1224 for a DEC RZ55.
  3953. May be 1.
  3954. .ip "#trk/cyl" 10
  3955. The number of tracks per cylinder e.g., 15 for a DEC RZ55.
  3956. May be 1.
  3957. .ip "#sect/trk" 10
  3958. The number of sectors or blocks per track e.g., 36 for a DEC RZ55.
  3959. May be the number of \fIblocks\fR in the file.
  3960. .(x z
  3961. block in a file
  3962. .)x \*($n
  3963. A block is MIN_PAGESIZE bytes; 
  3964. MIN_PAGESIZE is defined in \fCsm_client.h\fR.
  3965. (This is determined by the Storage Manager, not by the device.)
  3966. \**
  3967. .(f
  3968. \**
  3969. The format of a volume does not affect performance with 
  3970. most modern disks.
  3971. The easiest way to format volumes it to use
  3972. use 1 cyl, 1 track/cyl, and let the sect/trk account
  3973. for the size of the entire volume.
  3974. .)f
  3975. .ip "#KB/pg" 10
  3976. \fBFor logformat only\fR.
  3977. This gives the page size for log pages, in kilobytes.
  3978. The value given here may be 4 or larger, and must be a power of 2.
  3979. .lp
  3980. Formatvol collects the format information from the options
  3981. in the configuration files,
  3982. after which it determines which volumes to format or to display
  3983. by processing the options
  3984. \*(lqvolume\*(rq and \*(lqdisplay\*(rq from the command line.
  3985. The options that formatvol understands are summarized in Table 2.
  3986. .(b
  3987. .TS
  3988. box, center, tab(;);
  3989. c|c|c
  3990. c|c|c
  3991. l|l|l.
  3992. Option;Option;Option
  3993. Name;Type;Description
  3994. _
  3995. tempformat;string,int,int,int;path,volid,#cyl,#trk/cyl,#sect/trk
  3996. dataformat;string,int,int,int;path,volid,#cyl,#trk/cyl,#sect/trk
  3997. logformat;string,int,int,int,int;path,volid,#cyl,#trk/cyl,#sect/trk,#KB/pg
  3998. volume;int;volume to format - command line only
  3999. display;int;volume to display - command line only
  4000. .TE
  4001. .ce 2
  4002. \fBTable 2: Formatvol Options.\fR 
  4003. Fields are separated by white space, commas, colons or semicolons.
  4004. .)b
  4005. .(x z
  4006. options, formatvol
  4007. .)x \*($n
  4008. .sp
  4009. For example, 
  4010. to print information about the volumes with volids 8000 and 4000 use:
  4011. .(b I
  4012. \fCformatvol -dis 8000 -dis 4000\fR
  4013. .)b
  4014. .lp
  4015. To format a data volume with volid 8000 and 
  4016. a temporary volume with volid 4000 use:
  4017. .(x z
  4018. temporary volume
  4019. .)x \*($n
  4020. .(b I
  4021. \fCformatvol -vol 8000 -vol 4000\fR
  4022. .)b
  4023. .lp
  4024. Formatting a volume writes a volume header and initializes
  4025. the bitmaps that describe the free blocks on the volume.
  4026. A volume that is reformatted after being used loses all its data.
  4027. .lp
  4028. The Storage Manager does not prevent a volume from being formatted
  4029. while it is in use by a server, even though \fBit will cause 
  4030. the server to crash unrecoverably\fR.  
  4031. Be certain that a volume is not mounted before you format it! \**
  4032. .(f
  4033. \** The Storage Manager ought to lock volumes with Unix file locks,
  4034. but Unix does not provide an adequate mechanism for locking and
  4035. unlocking files in the context of crash recovery.
  4036. .)f
  4037. A volume is unmounted when all clients that are using the volume 
  4038. have completed transactions on it and have unmounted it.
  4039. (A client may unmount a volume explicitly with sm_DismountVolume(\ ),
  4040. or by shutting down with sm_ShutDown(\ ) or \fIexit(\ )\fR.)
  4041. .lp
  4042. During recovery, 
  4043. a server mounts the volumes that need recovery.
  4044. The volumes are dismounted when recovery is completed.
  4045. If a volume was in use at the time its server crashed,
  4046. \fBdo not reformat the volume until a new server recovers the
  4047. data on that volume\fR.
  4048. If you do, the server's log will be inconsistent with the data
  4049. on the volume, and the server will crash during recovery, and 
  4050. it will be unable to recover from that.
  4051. You can reformat the data volumes and the log volume to get
  4052. a server running again, but you will have lost all data on the volumes.
  4053. .lp
  4054. The log volume is mounted whenever the server is running,
  4055. so a log volume can be formatted ONLY when the server is not running.
  4056. .br
  4057. .sh 3 "Size Requirements for Log Volumes"
  4058. .lp
  4059. How large should a log volume be?
  4060. .(x z
  4061. log volume, size of
  4062. .)x \*($n
  4063. .(x z
  4064. log space
  4065. .)x \*($n
  4066. The answer depends on the expected transaction mix.  
  4067. More specifically, it depends on the age of the oldest 
  4068. (longest running) transaction
  4069. in the system and the amount of 
  4070. log space used by all active transactions.  
  4071. Here are some general rules to determine 
  4072. the amount of free log space available in the system.
  4073. .np
  4074. The physical log is circular.
  4075. Log space between the first log record generated 
  4076. by the oldest active transaction
  4077. and 
  4078. the most recent log record generated by any transaction cannot
  4079. be reused.
  4080. .np
  4081. Log space for a transaction is available for reuse when the 
  4082. transaction has committed or completely aborted.
  4083. Aborting a transaction causes log space to be used, so 
  4084. space is \fIreserved\f for aborting each transaction.
  4085. Enough log space must be
  4086. available to commit \fIor abort\fR all active transactions
  4087. at all times.
  4088. .np
  4089. Only space starting at the \fIbeginning\fR of the log can be reused.
  4090. This space can be reused if
  4091. it contains log records only for transactions meeting rule 2.
  4092. .np
  4093. All sm_WriteObject(\ ) calls require log space twice the
  4094. size of the space written in the object.  
  4095. All calls that create, grow, or shrink objects
  4096. require log space equal to the size created, inserted, or deleted.
  4097. Log records generated by these calls (generally one per call) 
  4098. have an overhead of approximately 50 bytes.
  4099. .np
  4100. File operations are logged, but the space requirements for 
  4101. them are most often negligible, since they are relatively rare
  4102. operations, and are often performed in short transactions.
  4103. .np
  4104. The amount of log space \fIreserved\fR for aborting a
  4105. transaction is equal to 
  4106. the amount of log space generated by the transaction (for
  4107. the purpose of committing the transaction).
  4108. .np
  4109. When insufficient log space is available 
  4110. for a transaction, the transaction is aborted.
  4111. .np
  4112. The log should be at least 1 Mbyte (250 pages).
  4113. .lp
  4114. For example, consider a transaction T1, which creates 300
  4115. objects of size 2,000 bytes, writes 20 bytes in 100 objects,
  4116. and is committed.  
  4117. T1 requires at 615 Kbytes for the creates
  4118. and 9 Kbytes of log space for the writes.  
  4119. Since log space must be reserved to abort the transaction, 
  4120. the log size must be over 1.248 Mbytes to run this transaction.  
  4121. Assuming T1 is the only transaction running in the system, 
  4122. all the log space it uses and reserves becomes available when it 
  4123. completes.
  4124. If another transaction, T2, is started at the same time
  4125. as T1, but is still running after T1 is committed, only the
  4126. reserved space for T1 is available for other transactions.  The
  4127. portion of the log
  4128. used by T1 and T2 is not available until T2 is finished.
  4129. .lp
  4130. Transactions that fail because of insufficient log space are commonly
  4131. those that load a large number of objects into 
  4132. a file during the
  4133. creation of a database.  
  4134. A solution to this problem is to load the
  4135. file in a series of smaller transactions.  
  4136. When the last transaction is committed, the load is complete.  
  4137. If the load needs to be aborted, a
  4138. separate transaction is run to destroy the file.
  4139. .br
  4140. .sh 3 "Backing Up Volumes"
  4141. .lp
  4142. The Storage Manager does not support media recovery,
  4143. .(x z
  4144. volumes, backing up
  4145. .)x \*($n
  4146. so backing up critical data volumes is wise.  
  4147. A volume may be backed up when it is unmounted and needs no recovery.
  4148. If a volume is stored on a Unix file, a simple copy
  4149. of the file can be used as a backup.  
  4150. For volumes stored on a raw disk partition, 
  4151. the Unix \fIdd(1)\fR command can be used to backup the volume to a
  4152. Unix file and to restore it.  
  4153. For example, to save a copy of the raw device 
  4154. \fC/dev/rrz4d\fR in the Unix file backup.rrz4d use: 
  4155. .(b
  4156. \fCdd if=/dev/rrz4d of=backup.rrz4d\fR.  
  4157. .)b
  4158. To restore the backup, use: 
  4159. .(b
  4160. \fCdd if=backup.rrz4d of=/dev/rrz4d\fR.
  4161. .)b
  4162. .sp
  4163. .sh 2 "Using the Server"
  4164. .lp
  4165. In this section we explain how to operate a Storage Manager server.
  4166. For the purpose of this discussion, we use only one server,
  4167. although any number of servers can be used to manage any number
  4168. of volumes.
  4169. We begin with starting and configuring the server.  
  4170. Next, we discuss what the server does during normal operation.  
  4171. We follow this with instructions for shutting the server down.  
  4172. Finally, we explain how the server recovers from failure.
  4173. .sh 3 "Starting the Server"
  4174. .lp
  4175. The server is composed of
  4176. two executable files: 
  4177. \fCsm_server\fR and \fCdiskrw\fR.  
  4178. .(x z
  4179. disk process
  4180. .)x \*($n
  4181. \fCSm_server\fR is the main server program.
  4182. \fCDiskrw\fR is started by the server, 
  4183. as a separate process for each mounted volume, 
  4184. for performing asynchronous disk I/O.  
  4185. These processes communicate with the server through sockets, semaphores,
  4186. and shared memory.  
  4187. By default, the server assumes \fCdiskrw\fR is located in the user's path.  
  4188. .(x z
  4189. default path for diskrw
  4190. .)x \*($n
  4191. An option, described below, can be used to change this assumption.  
  4192. .lp
  4193. When the server is started, it processes configuration options.  
  4194. .(x z
  4195. configuration options
  4196. .)x \*($n
  4197. These options are discussed further below.  
  4198. Second, the server allocates the buffer pool.  
  4199. The buffer pool is located in shared memory, so the operating 
  4200. system must have shared-memory support.  
  4201. Furthermore, the machine on which the server runs
  4202. must have enough shared memory to accommodate the
  4203. entire buffer pool.
  4204. If not enough shared memory is available, the
  4205. server prints a message, indicating how much shared memory
  4206. it is trying to acquire, and exits.
  4207. .lp
  4208. Third, the server mounts the log volume.  
  4209. .(x z
  4210. log volume
  4211. .)x \*($n
  4212. .(x z
  4213. regenerating log volume
  4214. .)x \*($n
  4215. .(x z
  4216. log volume, regenerated
  4217. .)x \*($n
  4218. If the log volume is newly formatted, it is \fIregenerated\fR.  
  4219. When a log volume is regenerated, 
  4220. the entire log is cleared and written to disk.  
  4221. This will take noticeable time if the volume is large.  
  4222. If the log is not regenerated, recovery analysis is performed.  
  4223. .lp
  4224. If no volumes require recovery,
  4225. .(x z
  4226. recovery
  4227. .)x \*($n
  4228. all phases of recovery complete in less than one second. 
  4229. If the analysis determines that any volumes require recovery
  4230. (due to a previous failure of some sort:
  4231. operating system failure, machine failure, 
  4232. internal error, or because a user killed the server),
  4233. recovery is performed.  
  4234. Data volumes that were mounted at the time of the failure
  4235. are remounted, 
  4236. updates by committed transactions are restored, 
  4237. and all transactions in progress at the time of failure are aborted.  
  4238. When recovery is complete, 
  4239. the data volumes are dismounted
  4240. and a checkpoint is taken.  
  4241. .lp
  4242. The server now begin to process requests from clients.
  4243. .br
  4244. .sh 3 "Configuring the Server"
  4245. .lp
  4246. There are several \fIconfiguration options\fR that
  4247. .(x z
  4248. configuration, options for server
  4249. .)x \*($n
  4250. can be set when the server is started.  
  4251. A brief description of the options is given in Table 3.  
  4252. Most options have default values, but some do not, and these
  4253. \fImust\fR be given values, either on the command line
  4254. or in a configuration file.
  4255. See 
  4256. Section 3 for general information that applies to all options.
  4257. .(z
  4258. .(x z
  4259. default, option values
  4260. .)x \*($n
  4261. .sz -2
  4262. .TS
  4263. box, center, tab(#);
  4264. c|c|c|c|c
  4265. c|c|c|c|c
  4266. l|l|l|l|l.
  4267. Option#Option#Possible#Default#Option
  4268. Name#Type#Values#Values#Description
  4269. _
  4270. config#string#file name#/usr/lib/sm_config#read a configuration file
  4271. ###$HOME/.sm_config#defaults is read unless
  4272. ###./.sm_config#skipdefault is set
  4273. verbose#Boolean#yes no#no#print configuration options 
  4274. bufpages#int#> 32#none#number of buffer pool pages 
  4275. logvolume#string#path name#none#name of the log volume
  4276. portname#string#name or number#exodussm#port name or port number
  4277. ####for a server; if a name, it
  4278. ####must be in \fC/etc/services\fR
  4279. errorfile#string#file name#- (stderr)#file for errors, 
  4280. ####warnings, progress
  4281. regenlog#Boolean#yes no#no#clear the log,
  4282. shutdown#Boolean#yes no#no#shut down after recovery 
  4283. ####or regeneration of log
  4284. checkpoints#int#> 1#100#checkpoint frequency
  4285. ####(based on number of log pages)
  4286. diskproc#string#file name#/usr/lib/exodus/diskrw#disk I/O program name
  4287. intercache#Boolean#yes no#yes#allow caching of pages
  4288. ####at the client between
  4289. ####transactions
  4290. progress#Boolean#yes no#no#control progress printing
  4291. maxclients#int#> 0#20#maximum number of 
  4292. ####clients to be served
  4293. ####simultaneously
  4294. maxthreads#int#> 1#function(maxclients)#maximum number of 
  4295. ####threads.
  4296. traceflags#int#hex number#0x0#set tracing flags.
  4297. ####Available if server is 
  4298. ####compiled with -DDEBUG.
  4299. tempformat#string###see Table 2.
  4300. dataformat#string###see Table 2.
  4301. logformat#string###see Table 2.
  4302. maxaddvolumes#int#small number >= 0#0#increases volume table size
  4303. wrapcount#int#>=0#0#starting wrap count for log
  4304. .TE
  4305. .sz +2
  4306. .ce
  4307. .uh "Table 3: Server Options"
  4308. .(x z
  4309. options, server
  4310. .)x \*($n
  4311. .)z
  4312. .lp
  4313. Option values are read from the the default configuration files 
  4314. \fC/usr/lib/sm_config\fR, \fC$HOME/.sm_config\fR, and \fC./.sm_config\fR
  4315. in that order, if they exist.  
  4316. If the command-line option \*(lqskipdefault\*(rq is given, 
  4317. .(x z
  4318. configuration files, skipping defaults
  4319. .)x \*($n
  4320. .(x z
  4321. default configuration files, skipping
  4322. .)x \*($n
  4323. these default files are not read.
  4324. .lp
  4325. Options on the command line are read after the default
  4326. files are read.
  4327. Command-line options are prefixed by a \*(lq-\*(rq.  
  4328. In addition to options,  
  4329. a server accepts the command-line \fIflags\fR given in Table 4.  
  4330. Command-line flags are prefixed by a \*(lq-\*(rq.
  4331. .(z
  4332. .sz -2
  4333. .TS
  4334. box, center, tab(#);
  4335. c|c
  4336. c|c
  4337. l|l.
  4338. Flag#Flag
  4339. Name#Effect
  4340. _
  4341. help#print a message and exit
  4342. skipdefault#do not read default configuration files
  4343. #must be the first argument on the command line
  4344. force#do not confirm log regeneration option
  4345. background#put in background (for use with Bourne shell)
  4346. .TE
  4347. .sz +2
  4348. .ce
  4349. .uh "Table 4: Server Command-Line Flags"
  4350. .(x z
  4351. flags, server command-line
  4352. .)x \*($n
  4353. .)z
  4354. .lp
  4355. When given the
  4356. \*(lqhelp\*(rq flag,
  4357. a server prints a list of the available options and flags,
  4358. and exits.
  4359. .lp
  4360. The \*(lqskipdefault\*(rq flag prevents a server from
  4361. reading the default configuration files.  
  4362. It must be the first argument on the command line if it is used.
  4363. .lp
  4364. The \*(lqforce\*(rq flag prevents a server from checking with
  4365. the user before regenerating the log.
  4366. .lp
  4367. The \*(lqbackground\*(rq  flag 
  4368. causes the server to disconnect from its controlling terminal.
  4369. This flag is available for users who run the server from
  4370. shells that, like the Bourne shell, do not have real job control.
  4371. .lp
  4372. We now describe each option from Table 2.
  4373. .lp
  4374. The \*(lqconfig\*(rq option specifies a configuration file to read after
  4375. default configuration files have been read.
  4376. .(x z
  4377. configuration file, which to read 
  4378. .)x \*($n
  4379. This option is effective only on the command line.
  4380. .lp
  4381. The \*(lqverbose\*(rq option is used to turn on and off printing of the
  4382. option values at startup.  
  4383. Options are printed to the file specified by \*(lqerrorfile\*(rq option (q.v.).
  4384. .lp
  4385. The \*(lqbufpages\*(rq option indicates the number of MIN_PAGESIZE 
  4386. pages to be used for a server's buffer pool.  
  4387. The option must be given for a server to run.  This option
  4388. determines the size of the shared memory segment allocated by the
  4389. server.  The shared memory segment will be MIN_PAGESIZE*bufpages bytes
  4390. long plus a few KB extra.
  4391. Section 5.3, \fBTuning the Server\fR,
  4392. for more information about setting this option.
  4393. .lp
  4394. The \*(lqlogvolume\*(rq option gives the path name of the volume 
  4395. that contains the log.  
  4396. A value must be given for the log volume.
  4397. .lp
  4398. The \*(lqportname\*(rq option indicates a port number or
  4399. the symbolic name of a port entry in \fC/etc/services\fR.
  4400. The server connects to this port and listens for client requests on it. 
  4401. To enable clients to locate a server with a symbolic
  4402. port name, the port name must to present in \fC/etc/services\fR
  4403. on both the client and server machines.  
  4404. If no port name is given, 
  4405. a server looks for an entry \*(lqexodussm\*(rq, registered for use with TCP,
  4406. in \fC/etc/services\fR.
  4407. .lp
  4408. By using port numbers instead of symbolic names avoids the
  4409. need for entries in \fC/etc/services\fR.  
  4410. See the Unix manual page for services(5).  
  4411. An example entry for the default
  4412. server name is:
  4413. .(b
  4414. \fCexodussm    1152/tcp            # exodus storage manager\fR
  4415. .)b
  4416. .lp
  4417. The \*(lqerrorfile\*(rq option directs server error messages and
  4418. diagnostics to the given file.  
  4419. A value of \*(lq-\*(rq means that \fIstderr\fR is used.
  4420. .lp
  4421. The \*(lqregenlog\*(rq option causes the log on the log volume to be
  4422. regenerated.  
  4423. \fBThis overwrites all log records, so it 
  4424. should not be done unless the server was last shut down cleanly\fR.
  4425. Server automatically regenerate their logs when
  4426. they are started with a newly formatted log volumes.
  4427. When the option is set to \*(lqyes\*(rq, a confirmation is requested.  
  4428. The confirmation can be disabled by starting the server with
  4429. the \*(lqforce\*(rq option.
  4430. .lp
  4431. The \*(lqshutdown\*(rq option causes a server to shut down immediately
  4432. after performing recovery or regenerating the log.
  4433. .lp
  4434. The \*(lqcheckpoints\*(rq option sets the checkpoint frequency for
  4435. a server.  
  4436. The value represents the number of log pages written
  4437. between checkpoints.
  4438. .lp
  4439. The \*(lqprogress\*(rq option causes a server to print messages
  4440. tracing its progress.  
  4441. This is used for debugging; it slows the server.
  4442. .lp
  4443. The \*(lqdiskproc\*(rq option specifies the path name of the disk I/O
  4444. program to be used by the server.
  4445. .lp
  4446. The \*(lqintercache\*(rq option allows experiments to be run
  4447. with and without inter-transaction caching of 
  4448. pages on the client.
  4449. .lp
  4450. The \*(lqmaxclients\*(rq option determines the number of clients
  4451. a server can server at any one time.
  4452. Servers create internal tables whose size depends on this value.
  4453. .lp
  4454. The \*(lqmaxthreads\*(rq value, determined by the \*(lqmaxclients\*(rq
  4455. value, should be sufficient, but can be overridden.
  4456. If a server recovers from a failure without running out
  4457. of threads, it has enough threads to handle client requests.
  4458. If numerous distributed transactions are active at the time
  4459. .(x z
  4460. transactions, distributed
  4461. .)x \*($n
  4462. .(x z
  4463. distributed transactions
  4464. .)x \*($n
  4465. of a server failure, it is possible, but unlikely,
  4466. that the server will
  4467. not be able to recover with the default number of threads.
  4468. .lp
  4469. The \*(lqtraceflags\*(rq option is available only with a server
  4470. that was compiled with debugging (the -DDEBUG flag).
  4471. It is useful for programmers who are modifying the Storage
  4472. Manager source code and testing their changes.
  4473. .lp
  4474. The \*(lqdataformat\*(rq, \*(lqlogformat\*(rq, and \*(lqtempformat\*(rq
  4475. options are as described in 
  4476. Section 5.1.5,  \fBFormatting Volumes\fR.
  4477. Servers can mount and use volumes given in these options.
  4478. .lp
  4479. The \*(lqmaxaddvolumes\*(rq option
  4480. indicates how large the mount table will be.
  4481. The server reads its configuration files, counts the volumes
  4482. named in the format options, and creates a mount table 
  4483. large enough to mount this many volumes and \*(lqmaxaddvolumes\*(rq more.
  4484. This is a strict limit to the number of volumes that the server can
  4485. mount (at any one time) as long as it is running.
  4486. The value of  \*(lqmaxaddvolumes\*(rq should not be boosted 
  4487. frivolously, because the size of the mount table affects
  4488. the amount of shared memory required by the server.
  4489. The default value is 0.
  4490. .lp
  4491. The \*(lqwrapcount\*(rq option is rarely needed.
  4492. The server will tell you if you ever need to set this option.
  4493. It is needed if you add volumes after
  4494. the server starts (maxaddvolumes > 0), 
  4495. and a volume that you are add was updated by a server 
  4496. running on a log that differs from the current log 
  4497. (or the log was regenerated since the added volume was last mounted.)
  4498. .sp
  4499. .sh 3 "Normal Operation of Servers"
  4500. .lp
  4501. During normal operation, servers listen for connections and
  4502. requests from clients and  monitor terminal input.
  4503. Error messages are printed on the servers terminals when
  4504. interesting events occur, for example, when a deadlock is
  4505. detected, or a transaction is aborted by a server because of 
  4506. a problem such as insufficient log space.
  4507. .sh 4 "Server Commands"
  4508. .lp
  4509. The following commands can be invoked from the standard input to the
  4510. server:
  4511. \*(lqhelp\*(rq, 
  4512. \*(lqshutdown\*(rq, \*(lqkill\*(rq, \*(lqcrash\*(rq,
  4513. \*(lqcheckpoint\*(rq, 
  4514. \*(lqprintstats\*(rq, \*(lqclearstats\*(rq,  
  4515. \*(lqprogress\*(rq,
  4516. \*(lquser\*(rq,
  4517. \*(lqaddvolume\*(rq,
  4518. \*(lqrmvolume\*(rq,
  4519. \*(lqlistvolumes\*(rq,
  4520. \*(lqlistmount\*(rq,
  4521. \*(lqlistdistr\*(rq,
  4522. \*(lqsource\*(rq, 
  4523. \*(lqredirect\*(rq.
  4524. When the server is compiled with
  4525. profiling (-DPROFIL, -p), the server accepts the \*(lqprofil\*(rq command.
  4526. When the server is compiled with debugging
  4527. (-DDEBUG), the server also accepts the
  4528. \*(lqtraceflags\*(rq and \*(lqtracelevel\*(rq commands.
  4529. \." TODO: add tracelevel as regular option
  4530. .lp
  4531. The \*(lqhelp\*(rq command provides a list of the
  4532. commands.  
  4533. .lp
  4534. The \*(lqshutdown\*(rq command instructs the server to abort all 
  4535. active transactions and cleanly shut down.
  4536. The \*(lqkill\*(rq command causes the server to halt immediately after
  4537. displaying the status of mounted volumes.
  4538. The \*(lqcrash\*(rq command has the same effect as the \*(lqkill\*(rq command,
  4539. except that
  4540. a core dump is produced as well.
  4541. .lp
  4542. The \*(lqcheckpoint\*(rq command causes the server to take a checkpoint
  4543. immediately.
  4544. Checkpoints are taken periodically by servers.  
  4545. The default frequency is once every 100 log pages, but this
  4546. .(x z
  4547. checkpoint 
  4548. .)x \*($n
  4549. .(x z
  4550. checkpoint frequency, default
  4551. .)x \*($n
  4552. .(x z
  4553. default checkpoint frequency
  4554. .)x \*($n
  4555. can be changed by an application program 
  4556. (see sm_ChangeCheckpointFrequency(\ ) in 
  4557. Section 4.11.2, \fBAdministrative Operations\fR).
  4558. .lp
  4559. The \*(lqprintstats\*(rq command prints general server statistics.
  4560. The \*(lqclearstats\*(rq command clears any counters among the statistics.
  4561. .lp
  4562. The \*(lqprogress\*(rq command reverses the value of the
  4563. \*(lqprogress\*(rq option.  
  4564. .lp
  4565. The \*(lquser\*(rq command reverses the value of an internal
  4566. flag that determines whether or not the server prints a message
  4567. when a user (application) error is encountered.
  4568. (There is no option to control this.)
  4569. .\" TODO: add a regular 'user' option
  4570. .lp
  4571. The \*(lqaddvolume\*(rq command 
  4572. adds a volume to the server's table of mountable volumes.
  4573. The \*(lqaddvolume\*(rq command
  4574. takes a format-option name
  4575. and a format-option value.
  4576. For example, to add the data volume 8000, type
  4577. .(b
  4578. \fCaddvolume dataformat /path/to/datafile:8000:1:1:300\fR
  4579. .)b
  4580. A volume cannot be added if the given format information
  4581. conflicts with other information in the table.
  4582. .lp
  4583. The \*(lqrmvolume\*(rq command 
  4584. removes a volume from
  4585. the server's table of mountable volumes.
  4586. The command takes a volume identifier.
  4587. For example, to remove the data volume 8000, type
  4588. .(b
  4589. \fCrmvolume 8000
  4590. .)b
  4591. A volume cannot be removed if it is in use.
  4592. .lp
  4593. The \*(lqlistvolumes\*(rq command 
  4594. prints the server's table of mountable volumes.
  4595. .lp
  4596. The \*(lqlistmount\*(rq command prints a list of the
  4597. volumes that are in some state of use: mounted, 
  4598. being mounted or being dismounted.
  4599. It also prints the number of free \*(lqmount slots\*(rq, 
  4600. which indicates how many more volumes could be mounted
  4601. at any one time, given the server's configuration.
  4602. To allow more volumes to be mounted at once,
  4603. shut the server down, boost the value of 
  4604. the \*(lqmaxaddvolumes\*(rq option, and restart the server.
  4605. .lp
  4606. The \*(lqlistdistr\*(rq command prints information about 
  4607. prepared distributed transactions.
  4608. .(x z
  4609. transactions, distributed
  4610. .)x \*($n
  4611. .(x z
  4612. distributed transactions
  4613. .)x \*($n
  4614. These transactions consume space in the log, and
  4615. if they are not aborted or committed, eventually the
  4616. server will fail because it will have run out of log space.
  4617. .(x z
  4618. log space
  4619. .)x \*($n
  4620. See 
  4621. Section 4.3, \fBTransactions\fR,
  4622. Section 4.11.1, \fBExternal Two-Phase Commit Functions\fR
  4623. for information about distributed transactions.
  4624. .lp
  4625. The \*(lqsource\*(rq command takes one argument, the path name
  4626. of a file from which to read commands.
  4627. The server processes these commands, and when it reads the
  4628. last command in the file, it resumes reading from
  4629. the terminal.
  4630. If the path name is missing or is
  4631. \fC/dev/tty\fR, reading resumes from the terminal.
  4632. .lp
  4633. The  \*(lqredirect\*(rq command takes two arguments.
  4634. The first argument indicates which output stream is to
  4635. be redirected: messages to the terminal or 
  4636. error messages.
  4637. The second argument is the path name of a file
  4638. to which the output is written.
  4639. When the output is redirected again, the stream is flushed
  4640. to the given file and the file is closed.
  4641. To redirect output to the terminal, use \fC/dev/tty\fR
  4642. or omit the path name.
  4643. .lp
  4644. The  \*(lqprofil\*(rq command causes the server to dump
  4645. its profiling information to disk. 
  4646. This command is available only on a server that was compiled
  4647. with profiling on (-DPROFIL -p).
  4648. See the manual page for prof(1).
  4649. .lp
  4650. The  \*(lqtraceflags\*(rq command may take an integer argument,
  4651. which may be a hexadecimal number, such as \*(lq0xfa3\*(rq,
  4652. in which case it sets the server's trace flags word to that value.
  4653. The command is available only with a server that was compiled
  4654. with debugging on (-DDEBUG -g).
  4655. The meanings of the trace flags are found in the server's
  4656. source code, in \fCsrc/include/global_trace.h\fR.
  4657. When \*(lqtraceflags\*(rq is used with no argument, it prints the
  4658. value of the trace flags word.
  4659. .lp
  4660. The  \*(lqtracelevel\*(rq command is available with a server
  4661. that was compiled with debugging on (-DDEBUG -g).
  4662. When used with no argument, it prints
  4663. the trace level for the trace flags that are on.
  4664. When given an integer argument (1, 2, or 3),
  4665. it sets the trace level for the trace flags that are on.
  4666. .br
  4667. .sh 3 "Shutting Down the Server"
  4668. .lp
  4669. The server can be shut down several ways.
  4670. One method is to use one of the above-mentioned commands.  
  4671. Another is to run the \*(lqshutserver\*(rq program, described below,
  4672. at the end of this section.
  4673. A third way to shut down a server is to
  4674. call sm_ShutdownServer(\ ) in a client program.
  4675. .lp
  4676. A server may also shut itself down because of a fatal
  4677. error, such as the unexpected death of a disk process or a bug.
  4678. A fatal error causes the server to report the state of all
  4679. the mounted volumes, dump core, and exit.
  4680. .lp
  4681. The server allocates a Unix System V shared-memory segment and a
  4682. semaphore set when it starts.  
  4683. If a server is shut down in a controlled fashion,
  4684. it removes the segment and semaphore set.
  4685. These resources are not 
  4686. removed when the server is terminated 
  4687. by \fCkill -9 <server process>\fR typed in the shell,
  4688. by the \*(lqkill\*(rq or \*(lqcrash\*(rq command given to the server's terminal monitor,
  4689. or when the server process is killed by a debugger.
  4690. \fBIf you use any one of these means to terminate a
  4691. server, you must use ipcrm(1) to remove the 
  4692. resources.\fR
  4693. See the manual pages for ipcs(1) and ipcrm(1) for more
  4694. information.
  4695. If the segments and semaphore sets are not removed, 
  4696. eventually the operating system will run out of segments,
  4697. and you will be unable to start a new server.
  4698. .lp
  4699. If a server shuts down without 
  4700. having committed or aborted all its active transactions 
  4701. and flushed all its dirty pages to disk, 
  4702. recovery is required when the server is restarted.  
  4703. When a server shuts down, it prints the status of all the
  4704. mounted volumes.
  4705. It indicates if recovery is necessary on those volumes.
  4706. .br
  4707. .sh 4 "Running the Shutserver program"
  4708. .lp
  4709. The \fCshutserver\fR program is invoked:
  4710. .(b
  4711. \fCshutserver [-m machine] [-s servername] [-h]\fR.
  4712. .)b
  4713. The \*(lqmachine\*(rq specifies the name of the machine on which runs the
  4714. server to be shut down.  
  4715. If \*(lq-m machine\*(rq is not given, the program
  4716. uses the machine on which \fCshutserver\fR is executed.
  4717. The \*(lqservername\*(rq is the name of the server in \fC/etc/services\fR,
  4718. .\" TODO: this should be -port name.
  4719. If \*(lq-s servername\*(rq is not given, \*(lqexodussm\*(rq is used.
  4720. The \*(lq-h\*(rq option prints a brief help message.  
  4721. .br
  4722. .sh 3 "Recovery"
  4723. .lp
  4724. When a server is started after a failure it automatically performs recovery.  
  4725. The time it takes for recovery depends on several factors, including
  4726. the number of transactions in progress at the time of the failure,
  4727. the number of log records generated by these transactions, 
  4728. and the number of log records generated since the last checkpoint.
  4729. .lp
  4730. Recovery has three phases.  
  4731. .(x z
  4732. recovery 
  4733. .)x \*($n
  4734. After each phase, the server prints
  4735. information about the time and I/O operations required to perform the
  4736. phase.  
  4737. .lp
  4738. The first phase is \fIanalysis\fR. 
  4739. The log is scanned to determine what transactions were active
  4740. and which volumes were mounted at the time of the failure.  
  4741. .lp
  4742. After analysis, the volumes are mounted
  4743. and the \fIredo\fR phase is performed.  
  4744. In the redo phase,  
  4745. data are restored to their state at the time
  4746. of the failure.
  4747. .lp
  4748. In the last phase, the \fIundo\fR phase, 
  4749. the server aborts 
  4750. the transactions that were active at the time of the crash.
  4751. The volumes are dismounted, and a checkpoint is taken.
  4752. .lp
  4753. For details of recovery in the Storage Manager, see
  4754. [Fran92].
  4755. .br
  4756. .sh 2 "Tuning the Server"
  4757. .lp
  4758. There are several tuning parameters in the Storage Manager server.
  4759. The following sections describe each one.
  4760. .br
  4761. .sh 4 "The Size of the Buffer Pool"
  4762. .lp
  4763. The size of a server's buffer pool
  4764. is determined by the \*(lqbufpages\*(rq
  4765. option, which
  4766. indicates the number of MIN_PAGESIZE pages 
  4767. in the buffer pool.
  4768. If a server is the primary process on a machine, it
  4769. should have a buffer pool close to 
  4770. the size of available shared memory.
  4771. When both an application and a server are running on the
  4772. same machine, choosing a buffer pool size is more difficult.
  4773. \*(lqproper\*(rq
  4774. choice depends on the behavior of the applications
  4775. and their interactions with servers.
  4776. A good rule of thumb is that 
  4777. that clients should have the adequate
  4778. buffer space, to minimize client-server interaction.
  4779. .lp
  4780. The buffer pool must fit in the available shared memory
  4781. of the machine on which the server runs.
  4782. The server will let you know if it cannot acquire
  4783. enough shared memory when it starts.
  4784. See the manual  pages for
  4785. ipcs(1) and ipcrm(1) to find out how
  4786. much shared memory is in use.
  4787. See your
  4788. system administrator to find out 
  4789. how much shared memory has been configured for
  4790. your systems
  4791. if you find that you cannot
  4792. run a server with a buffer pool of adequate size,
  4793. and no shared memory segments are being wasted.
  4794. .br
  4795. .sh 4 "The Size of Log Pages"
  4796. .lp
  4797. The log page size is determined when a log volume is formatted.
  4798. For a transaction mix dominated by 
  4799. transactions that generate more than a few 
  4800. kilobytes of log information, the larger the log page size, the better.  
  4801. For short running transactions, 
  4802. such as those found in transaction processing benchmarks, 
  4803. 8 Kbyte log pages give good results.
  4804. .br
  4805. .sh 4 "Checkpoint Frequency"
  4806. .lp
  4807. The checkpoint frequency is based on the
  4808. number of log pages written.
  4809. The default frequency is every 100 log pages.
  4810. The frequency can be determined by setting the 
  4811. \*(lqcheckpoint\*(rq configuration option.
  4812. .(x z
  4813. checkpoint frequency
  4814. .)x \*($n
  4815. .(x z
  4816. default checkpoint frequency
  4817. .)x \*($n
  4818. It can be changed in a running server by an
  4819. application that calls sm_ChangeCheckpointFrequency(\ ).
  4820. More frequent checkpoints tend to shorten the time
  4821. required to recover after a server fails
  4822. at the expense of processing time during normal operation.
  4823. Checkpoints also cause the server's dirty pages to be flushed
  4824. to disk, which may also improve performance during normal
  4825. operation.
  4826. .bp
  4827. .sh 1 "REFERENCES"
  4828. .sp
  4829. .ip "[Care86]" 10
  4830. M. Carey, D. DeWitt, J. Richardson, and E. Shekita, 
  4831. \fIObject and File Management in the EXODUS Extensible Database System\fR, 
  4832. \fBProc. of the 1986 VLDB Conf.\fR,
  4833. Kyoto, Japan, Aug. 1986.
  4834. .ip "[Care89]" 10
  4835. M. Carey, D. DeWitt, E. Shekita, 
  4836. \fIStorage Management for Objects in EXODUS\fR,
  4837. \fBObject-Oriented Concepts, Databases, and Applications\fR,
  4838. W. Kim and F. Lochovsky, eds., Addison-Wesley, 1989.
  4839. .ip "[Chou85]" 10
  4840. H. Chou and D. Dewitt, 
  4841. \fIAn Evaluation of Buffer Management Strategies for Relational Database Systems\fR,
  4842. \fBProc. of the 1985 VLDB Conf.\fR, 
  4843. Stockholm, Sweden, Aug. 1985.
  4844. .ip "[Fran92]" 10
  4845. M. Franklin, M. Zwilling, C.K.Tan, M. Carey, and D. DeWitt,
  4846. \fICrash Recovery in Client-Server EXODUS\fR,
  4847. \fBProc. of the ACM SIGMOD Int'l. Conf. on Management of Data\fR,
  4848. San Diego, CA, June 1992.
  4849. .ip "[Gray78]" 10
  4850. J. N. Gray,
  4851. \fINotes on Database Operating Systems\fR,
  4852. \fBLecture Notes in Computer Science 60, 
  4853. Advanced course on Operating Systems\fR,
  4854. ed. G. Seegmuller, Springer Verlag, New York 1978.
  4855. .ip "[Gray88]" 10
  4856. J. Gray, R. Lorie, G. Putzolu, I. Traiger,
  4857. \fIGranularity of Locks and Degrees of Consistency in a Shared Data Base\fR,
  4858. \fBReadings in Database Systems\fR,
  4859. ed. M. Stonebraker, Morgan Kaufmann, San Mateo, Ca., 1988.
  4860. .ip "[Litw88]" 10
  4861. W. Litwin,
  4862. \fILinear Hashing: A New Tool for File and Table Addressing\fR,
  4863. \fBReadings in Database Systems\fR,
  4864. ed. M. Stonebraker, Morgan Kaufmann, San Mateo, Ca., 1988.
  4865. .ip "[Moha83]" 10
  4866. C. Mohan, B. Lindsay,
  4867. \fIEfficient Commit Protocols for the Tree of Processes 
  4868. Model of Distributed Transactions\fR,
  4869. \fBProc. 2nd ACM SIGACT/SIGOPS Symposium on Principles of Distributed
  4870. Computing\fR,
  4871. Montreal, Canada, August, 1983.
  4872. .ip "[Moha89]" 10
  4873. C. Mohan, D. Haderle, B. Lindsay, H. Pirahesh, and P. Schwarz,
  4874. \fIARIES: A Transaction Recovery Method Supporting
  4875. Fine-Granularity Locking and Partial Rollbacks Using Write-Ahead
  4876. Logging\fR, 
  4877. \fIACM Transactions on Database Systems\fR,
  4878. Vol. 17, No 1, March 1992.
  4879. .ip "[Rich87]" 10
  4880. J. Richardson and M. Carey,
  4881. \fIProgramming Constructs for Database System Implementation in EXODUS\fR,
  4882. \fBProc. of the ACM SIGMOD Int'l. Conf. on Management of Data\fR,
  4883. San Francisco, CA, May 1987.
  4884. .ip "[exoArch]" 10
  4885. \fIEXODUS Storage Manager Architecture Overview\fR, unpublished,
  4886. included in EXODUS Storage Manager software release.
  4887. .bp
  4888. .\" use alphabetic section header A.1, A.2, etc.
  4889. .af $1 A
  4890. .nr $1 0
  4891. .af $9 A
  4892. .nr $9 1
  4893. .sh 1 "APPENDIX : Locking Protocol for Storage Manager Operations"
  4894. .lp
  4895. The Storage Manager performs concurrency control using the standard
  4896. hierarchical two-phase locking protocol (see [Gray78], [Gray88])
  4897. .(x z
  4898. locking protocol
  4899. .)x \*($n Appendix
  4900. .(x z
  4901. two-phase locking protocol
  4902. .)x \*($x Appendix
  4903. for locking files and object pages.  
  4904. The lock hierarchy contains two granularities: file-level, and page-level.  
  4905. Locking for index operations is performed with a non-two-phase protocol,
  4906. that allows multiple clients to read and update the same index.  
  4907. This section describes the lock modes used in the system, 
  4908. lists the locks requested for each Storage Manager 
  4909. file and object operation, 
  4910. and explains how deadlocks are handled.  
  4911. .(x z
  4912. deadlock
  4913. .)x \*($n Appendix
  4914. Lock acquisition and release are \fIimplicit\fR in 
  4915. all relevant operations, so clients cannot explicitly manage their own locks.
  4916. .br
  4917. .sh 2 "Lock Modes"
  4918. .lp
  4919. Files are locked in one of six modes: no lock (NL), shared (S),
  4920. exclusive (X), intent to share (IS), intent to exclusive (IX),
  4921. .(x z
  4922. lock, exclusive
  4923. .)x \*($n Appendix
  4924. share with intent to exclusive (SIX) [Gray78], [Gray88].  Only shared and
  4925. exclusive locks are obtained on pages.  Determining whether two locks
  4926. are compatible (eg., when a client holds a lock on a file and another
  4927. client wants to obtain a lock on it as well) can be done using
  4928. a table.  
  4929. Table \n($9.1 is a lock compatibility table for the six file
  4930. lock modes.  Each row indicates a lock that some client can hold,
  4931. and each column indicates a lock desired by another client.  The Y and
  4932. N table entries indicate (yes or no) whether the locks are compatible
  4933. or not. 
  4934. .\" ) to match open paren in Table reference above
  4935. .(z
  4936. .TS
  4937. center, tab(#), box ;
  4938. c s s s s s s
  4939. c|c s s s s s
  4940. c|c c c c c c
  4941. l|l l l l l l.
  4942.  
  4943. Lock#Lock Requested
  4944. Held#NL#IS#IX#S#SIX#X
  4945. _
  4946. NL#Y#Y#Y#Y#Y#Y
  4947.  
  4948. IS#Y#Y#Y#Y#Y#N
  4949.  
  4950. IX#Y#Y#Y#N#N#N
  4951.  
  4952. S#Y#Y#N#Y#N#N
  4953.  
  4954. SIX#Y#Y#N#N#N#N
  4955.  
  4956. X#Y#N#N#N#N#N
  4957. .TE
  4958. .ce
  4959. .uh "Table \n($9.1: Lock Compatibility"
  4960. .\" ) to match open paren in .uh above
  4961. .)z
  4962. .lp
  4963. Another table can be used to express lock convertibility.  
  4964. A lock conversion occurs when a client holds a lock in some mode and 
  4965. requests an operation that requires a different mode for the lock. 
  4966. Table \n($9.2 is a lock convertibility table for the six file lock modes. 
  4967. Each row indicates a lock that the client already holds and each column
  4968. indicates the new lock mode requested.  The entries represent the
  4969. resulting lock mode obtained.
  4970. .\" ) to match open paren Table ref above
  4971. .(z
  4972. .TS
  4973. center, tab(#), box ;
  4974. c s s s s s s
  4975. c|c s s s s s
  4976. c|c c c c c c
  4977. l|l l l l l l.
  4978.  
  4979. Lock#Lock Requested
  4980. Held#NL#IS#IX#S#SIX#X
  4981. _
  4982. NL#NL#IS#IX#S#SIX#X
  4983.  
  4984. IS#IS#IS#IX#S#SIX#X
  4985.  
  4986. IX# IX#IX#IX#SIX#SIX#X
  4987.  
  4988. S# S#S#SIX#S#SIX#X
  4989.  
  4990. SIX#SIX#SIX#SIX#SIX#SIX#X
  4991.  
  4992. X#X#X#X#X#X#X
  4993. .TE
  4994. .ce
  4995. .uh "Table \n($9.2: Lock Convertibility"
  4996. .\" ) to match open paren in .uh above
  4997. .)z
  4998. .sp
  4999. .br
  5000. .sh 2 "Locks Obtained by Operations"
  5001. .lp
  5002. The locks mentioned above are obtained on two types of structures in
  5003. the Storage Manager: files and pages.  
  5004. Only the pages that contain object headers and root 
  5005. entries are locked; large object data pages 
  5006. and file index pages are not locked.
  5007. The entire root entry page is locked 
  5008. when a root entry is used.  
  5009. .lp
  5010. Table \n($9.3 lists all of the locks 
  5011. .\" ) to match open paren above
  5012. obtained by the various Storage Manager operations.
  5013. The column labelled \*(lqFile Lock\*(rq
  5014. indicates what lock mode is used for locking
  5015. the file in question.
  5016. The column labelled \*(lqPage Lock\*(rq
  5017. indicates what lock mode is used for locking
  5018. pages containing the objects or root entries in question.
  5019. Locks are held until the end of the transaction in which they were
  5020. acquired.
  5021. .lp
  5022. Some applications may find it necessary to acquire more
  5023. restrictive locks on pages and files to avoid conflicts
  5024. during lock-upgrade requests.  
  5025. For example, consider an application that reads an object (with
  5026. sm_ReadObject(\ )) and subsequently writes it (with sm_WriteObject(\ )).  
  5027. When the object is read, a share lock is acquired for the object's page.  
  5028. .(x z
  5029. lock, share
  5030. .)x \*($n Appendix
  5031. When the object is written, a lock-upgrade request is 
  5032. sent to the server to obtain an exclusive lock on the page.
  5033. .(x z
  5034. lock, exclusive
  5035. .)x \*($n Appendix
  5036. This extra message is relatively expensive and can lead to
  5037. potential deadlock if other clients are locking the page as well.
  5038. .(x z
  5039. deadlock
  5040. .)x \*($n Appendix
  5041. To avoid this problem, 
  5042. the 
  5043. \*(lqpagelock\*(rq option can be used
  5044. to change the default lock modes used when 
  5045. .(x z
  5046. default lock mode
  5047. .)x \*($n Appendix
  5048. the client library locks a page.
  5049. See Table 1 and the discussion of client options
  5050. in 
  5051. Section 4.2, \fBInitialization and Shutdown Operations\fR
  5052. for information about setting client options.
  5053. See Appendix A for more information about lock modes and the
  5054. Storage Manager's locking protocols.
  5055. .(z
  5056. .TS
  5057. box, center, tab(#) ;
  5058. c s s s
  5059. c c c c
  5060. l l l l.
  5061.  
  5062. Operation#File Lock#Page Lock#Comments
  5063. _
  5064. sm_Initialize(\ )#-#-#no locks needed
  5065. sm_ShutDown(\ )#-#-#no locks needed
  5066. sm_OpenBufferGroup(\ )#-#-#no locks needed
  5067. sm_CloseBufferGroup(\ )#-#-#no locks needed
  5068.  
  5069. sm_SetRootEntry(\ )#-#X#root entry page
  5070. sm_GetRootEntry(\ )#-#S#root entry page
  5071. sm_RemoveRootEntry(\ )#-#X#root entry page
  5072.  
  5073. sm_CreateFile(\ )#X#-#
  5074. sm_DestroyFile(\ )#X#-#
  5075.  
  5076. sm_GetFirstOid(\ )#S#-#
  5077. sm_GetLastOid(\ )#S#-#
  5078. sm_GetNextOid(\ )#S#-#
  5079. sm_GetPreviousOid(\ )#S#-#
  5080.  
  5081. sm_OpenScan(\ )#S#-#
  5082. sm_OpenScanWithGroup(\ )#S#-#
  5083. sm_ScanNextObject(\ )#-#-#no locks needed
  5084. sm_CloseScan(\ )#-#-#no locks needed
  5085.  
  5086. sm_OpenLoad(\ )#X#-#
  5087. sm_LoadNextObject(\ )#-#-#no locks needed
  5088. sm_CloseLoad(\ )#-#-#no locks needed
  5089.  
  5090. sm_CreateObject(\ )#IX#X#unordered file
  5091. sm_DestroyObject(\ )#IX#X#
  5092. sm_ReadObject(\ )#IS#S#
  5093. sm_ReadObjectHeader(\ )#IS#S
  5094. sm_ReleaseObject(\ )#-#-#no locks needed
  5095. sm_WriteObject(\ )#IX#X#
  5096. sm_InsertInObject(\ )#IX#X#
  5097. sm_AppendToObject(\ )#IX#X#
  5098. sm_DeleteFromObject(\ )#IX#X#
  5099.  
  5100. sm_CreateVersion(\ )#IX#X#
  5101. sm_FreezeVersion(\ )#IX#X#
  5102. .TE
  5103. .ce
  5104. .uh "Table \n($9.3: Locks Obtained by Operations"
  5105. .\" ) to match open paren above
  5106. .)z
  5107. .(x z
  5108. locks obtained by functions
  5109. .)x \*($n Table
  5110. .sp
  5111. .br
  5112. .sh 2 "Deadlock Detection and Avoidance"
  5113. .lp
  5114. With each lock request, a server analyzes its
  5115. local waits-for graph and detects local cycles, or \*(lqlocal deadlocks\*(rq.
  5116. .(x z
  5117. deadlock avoidance
  5118. .)x \*($n Appendix
  5119. .(x z
  5120. deadlock detection
  5121. .)x \*($n Appendix
  5122. The request that would cause a deadlock is denied (returns
  5123. esmFAILURE), 
  5124. and the client library returns esmLOCKCAUSEDDEADLOCK 
  5125. to the application in the global variable sm_errno. 
  5126. .lp
  5127. Distributed transactions may also cause a deadlock.
  5128. The servers do not detect deadlocks that involve other servers.
  5129. Global deadlocks are avoided by timing out locks.
  5130. Each request that awaits a lock is aged.
  5131. When its age exceeds the time given by the client's \*(lqlocktimeout\*(rq
  5132. option, the request is denied (returns esmFAILURE),
  5133. and the client library returns esmLOCKBUSY 
  5134. to the application in the global variable sm_errno. 
  5135. .lp
  5136. When an application's request fails with esmLOCKBUSY or esmLOCKCAUSEDDEADLOCK,
  5137. the application must abort its transaction, to free the locks
  5138. it holds, and it must start its transaction again.
  5139. .sp 3
  5140. .bp
  5141. .sh 1 "APPENDIX : Generation of Unique Numbers for OIDs"
  5142. .lp
  5143. The \*(lqunique\*(rq field of an OID is special 32-bit value that is generated
  5144. when the object is created and used to detect instances where the OID
  5145. has become dangling or corrupted.
  5146. The values that are stored in \*(lqunique\*(rq fields are generated by 
  5147. Storage Manager servers.  
  5148. Disk volumes are partitioned into blocks of 32
  5149. pages, and for each partition a 32-bit counter is maintained.  
  5150. When a new page is allocated, it is allotted a range (100) of unique
  5151. numbers to use during object creation.  
  5152. The counter in the partition containing the new page is incremented to reflect the allotment.  
  5153. When this allotment has been exhausted, 
  5154. a request is made to the server for another allotment.  
  5155. When an object is created in a particular
  5156. partition, the \*(lqunique\*(rq field of the new object's OID is set to the
  5157. next available number in the range on the page.  
  5158. While this strategy does not guarantee that OIDs 
  5159. are unique for all time, the
  5160. probability of a dangling OID that 
  5161. maps to the same page and the  same slot,
  5162. and has the same \*(lqunique\*(rq field as a valid OID is very low.
  5163. As a result, \*(lqunique\*(rq fields can be used virtually to guarantee 
  5164. the validity of an OID.  
  5165. We adopted this approach instead of using
  5166. unique-for-all-time logical OIDs with a surrogate 
  5167. index in order to avoid the extra disk I/Os that might be 
  5168. needed to translate a logical OID to a physical address.
  5169. .bp
  5170. .++P
  5171. .sp 0.5i
  5172. .ce 1
  5173. \fBTABLE OF CONTENTS\fR
  5174. .sp 2
  5175. .xp
  5176. .\" .bp
  5177. .\" .++P
  5178. .\" .sp 0.5i
  5179. .\" .ce 1
  5180. .\" \fBINDEX\fR
  5181. .\" .sp 2
  5182. .\" .xp z
  5183.